Hi, in a previous post, I asked something about checking if data is in a file, I would like to remove duplicate entries. Hwo on earth would I do that? I was thinking nested for loops, on loops through each line and inside another loop would compare each line to the current line. Is that what I need to do?
1. Use file() function to read a file. this will give the file data in array 2. Now use array_unique function. This will remove duplicate enntries. 3. Now write the contents of the array in to file.
From php.net I created this little function based on the one posted by chasesan at gmail dot com; It find all occurences of a string within another string and returns their positions as an array: <?PHP function findAllOccurences($Haystack, $needle, $limit=0) { $Positions = array(); $currentOffset = 0; $count=0; while(($pos = strpos($Haystack, $needle, $offset)) && ($count < $limit || $limit == 0)) { $Positions[] = $pos; $offset = $pos + strlen($needle); $count++; } return $Positions; } ?> I hope this helps someone :) PHP: You should be able to use this to replace all occurrences with nothing, then since it tells you where the occurrences happened you can then add the first occurrence to the nothing you replaced it with.. I hope that makes sense i'm on a php high, also I haven't tested the code posted above.
Sounds great, but I'm a dummy. Can you provide an example script that I can pick apart? Thanks for your help.