Results 1 to 3 of 3
Aug 27, 2007, 02:52 #1
simple help with preg_replace and regex
I have this string:
$text = "banana pineapple fitness fat banana apple fat fatness";
And i want to cut all the repeated words, wich are "banana" and "fat".
How can i do it with regex and preg_replace or other php function?
Result should be:
$text = "banana pineapple fitness fat apple fatness";
$text = "pineapple fitness banana apple fat fatness";
(the order of the words doesnt need to be the same after the replacing process)
Aug 27, 2007, 03:06 #2
you don't need regular expressions here:
$arr = explode(" ", $text);
$arr2 = array_unique($arr);
$text2 = implode(" ", $arr2);
Never ascribe to malice,
that which can be explained by incompetence.
Your code should not look unmaintainable, just be that way.
Aug 27, 2007, 08:14 #3