Forum Moderators: coopster

Message Too Old, No Replies

Endless question mark :s

         

Jytho

12:21 pm on Nov 7, 2007 (gmt 0)

10+ Year Member



Greetings, I'm having troubles in understanding how can I realize a script that has to:

1) search any value in a file(note, not a defined one, it has to search for same words!)
2) remove any string that has that value in it.. but!
3) except the first string

Im googling here and there, but nothing cleaned my mind, Im still wondering how it could be done, and I dont have much time, dont wanna sick my superior
Can someone help me out?
Salut

PHP_Chimp

12:32 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you not use preg_match [php.net]
if you use it as -
preg_match($pattern, $subject, $matches);
Then you will have access to all of the matches in the $matches array. You could then use whatever parts of the array you need?

Jytho

2:12 pm on Nov 7, 2007 (gmt 0)

10+ Year Member



it is true that ereg_match returns the values that you are searching for, my problem is that I dont know how the content is.
for example, if I do have these lines

r4ndomone
rand0m two
Random two2
raNdom three
ranDom three2

the rows that contain same words, for example 'two' or 'three' turn me in troubles, cause looking for example for the word "chocolate" is of course easy.. but its less when you dont know what will be double

PHP_Chimp

2:39 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahh ok I think I understand better what you want.
How about looking at preg_split to return an array then you could search for duplicate values.

// $data = your input;
$words = preg_split('%\b%', $data, -1, PREG_SPLIT_NO_EMPTY);
$uniqWords = [url=http://uk3.php.net/manual/en/function.array-unique.php]array_unique[/url]($words);

$uniqWords should now be an array containing all of the words,
but no duplicates.
So you can do what you want with that array.

<edit>
Array_unique is case sensitive, but there is a function in the manual comments that can be used for a case insensitive version.

[edited by: PHP_Chimp at 2:45 pm (utc) on Nov. 7, 2007]