Forum Moderators: coopster

Message Too Old, No Replies

checking for double strings

         

j0hn

3:03 am on Nov 2, 2007 (gmt 0)

10+ Year Member



Hello,
Im trying to create a little cleaner for a log of mine,
The problem is, that I was thinking on how it was possible to check if there is a double string in my txt file, and in case, remove it.
I have troubles in this, cause in php documentation I just spotted string comparation beetwen 2 defined string, instead, I dont know what could be double
Any help is appreciated :)

joelgreen

9:33 am on Nov 2, 2007 (gmt 0)

10+ Year Member



Do you want to remove line from log file if log file has exactly the same line?

$text = array_unique(file('some.log'));

phparion

9:52 am on Nov 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you need to explode the file into an array and then run any built in array function or parse array with regex to kick out the duplicate lines.

joelgreen provided a very good and simple code to do this.

j0hn

1:45 pm on Nov 2, 2007 (gmt 0)

10+ Year Member



thank you, it worked like a charm!

One more question if im allowed to,

Ive also to check if the inital part of a string is the same of another one. Ive problems with this kind of stuff cause The script have to search for strings wich I dont know, and this is far more of what I was able to handle in strings stuff.
to check, lets say, the first 20 characters of every string, and remove every other line that begins with the same characters, how the script should look?
thank you in advance.

j0hn

1:28 am on Nov 4, 2007 (gmt 0)

10+ Year Member



mm Im still wondering on how that was possible, cause removing clones fixes a lot of my log's errors, but there are still other strings that re the same and differs a bit. any clue?