I'm looking to replace the 'nth' instance of an expression within a string.

Example (very simple)-

$string="My mom can beat up your mom and your mom's dog";
$pattern="mom";
$replacement="dad";

I want to be able to replace any particular instance of the pattern within that string. I was getting ready to do it in a very complex manner by finding all the matches, splitting on the pattern, and then breaking the string down and reassembling it in the proper order. It seems like there might be an easier way to perform this though.

Anyone have any suggestions?

Thanks-
Thaddeus Quintin


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



Reply via email to