Re: strip out repeated ocurrence of a string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 1/25/2010 10:48 PM, Camilo Sperberg wrote:
Hello list :)

I have this problem, a certain string can contain the following information:


$string = '
hi{value1;value2}
bye{value1;value3}
hi{value1;value4}
hi{value1;value2}
bye{value1;value2}
';

What I want is to be able to get this result:

$string = '
hi{value1;value2}
bye{value1;value3}
hi{value1;value4}
bye{value1;value2}
';

(the order of appearance doesn't matter)
Is it even possible to do this with regular expressions? Or should I first
look if there is some kind of match and then apply an
str_replace($match,'',$string) and add the $match again?

Greetings !


Assuming the duplicate segments are identical.....
I'd use explode() and convert the string to an array. Use "}" for the delimiter.
Then use array_unique()
And then use implode() to restore the string.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux