What are some common methods to remove duplicate entries from a text file using PHP?

Duplicate entries in a text file can be removed using PHP by reading the contents of the file, storing unique entries in an array, and then rewriting the file with the unique entries.

<?php
// Read the contents of the text file
$file = file_get_contents('data.txt');

// Convert the contents into an array
$lines = explode("\n", $file);

// Remove duplicates
$uniqueLines = array_unique($lines);

// Write the unique entries back to the file
file_put_contents('data.txt', implode("\n", $uniqueLines));
?>