Here's an example of how you could delete duplicate IP addresses in a file using PHP
Mark E.
Here's an example of how you could delete duplicate IP addresses in a file using PHP:
<?php
// Open the input file for reading
$inFile = fopen('TestNewIPs.txt', 'r');
// Create an empty array to store the unique IP addresses
$uniqueIps = array();
// Loop through each line in the input file
while ($line = fgets($inFile)) {
// Trim any whitespace from the beginning or end of the line
$line = trim($line);
// If the line (IP address) is not already in the array, add it
if (!in_array($line, $uniqueIps)) {
$uniqueIps[] = $line;
}
}
// Close the input file
fclose($inFile);
// Open a new output file for writing
$outFile = fopen('TestNewIPs_unique.txt', 'w');
// Loop through the array of unique IP addresses and write them to the output file
foreach ($uniqueIps as $ip) {
fwrite($outFile, $ip . "\n");
}
// Close the output file
fclose($outFile);
?>
This PHP code will read the input file line by line, trim any whitespace from the beginning or end of each line, and add it to an array of unique IP addresses if it hasn't been added already. Then, it will open a new output file and write each unique IP address to a new line in the file. Note that this code assumes that the input file is named TestNewIPs.txt
and that the output file should be named TestNewIPs_unique.txt
. You may need to adjust these filenames to match your specific use case.