mac_gabe Posted April 25, 2013 Share Posted April 25, 2013 (edited) I think I may have known how to do this once but I've definitely forgotten now. Please help. I have a text with many instance of "Adam" and "John" in it. In a single find-and-replace (I don't want to use 2 passes) I want to replace all instance of "Adam" with "x", and "John" with "y". In fact the actual example is a little more complex, but this will solve it. I'm struggling with this: $search="@(Adam)|(John)@"; $replace="@x|y@"; $text = preg_replace($search, $replace, $text); I know there should be a back reference - something like $1 or $2 in the replace term probably; but that's not going to produce the letters x or y. So I'm stuck. Thanks for any help. Edited April 25, 2013 by mac_gabe Quote Link to comment Share on other sites More sharing options...
Jessica Posted April 25, 2013 Share Posted April 25, 2013 (edited) str_replace Edited April 25, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
mac_gabe Posted April 25, 2013 Author Share Posted April 25, 2013 Thanks Jessica! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.