A question regarding search and replace

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ammar
Forum Newbie
Posts: 2
Joined: Sat Feb 19, 2005 6:48 am

A question regarding search and replace

Post 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
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
Post Reply