Page 1 of 1

A question regarding search and replace

Posted: Wed Mar 02, 2005 2:46 am
by ammar
Hi there,

I would like to be able to perform a substring search for lets say 'xyz', and then replace its first occurence with 'abc1', second with 'abc2'.. and so on. Is this possible somehow?

Regards

Ammar

Posted: Wed Mar 02, 2005 3:06 am
by anjanesh

Posted: Wed Mar 02, 2005 9:37 am
by feyd
preg_replace can only do this with a cleverly set pattern and replacement string.

preg_replace_callback() may be of a bit more use, as it does some of the trickery for you.

http://php.net/preg_replace_callback