Is it possible to preg replace unique variables into a string?

Posted by Scarface on Stack Overflow See other posts from Stack Overflow or by Scarface
Published on 2010-04-12T01:38:57Z Indexed on 2010/04/12 1:43 UTC
Read the original article Hit count: 250

Filed under:

What I want to do is use preg replace to replace matches within a string with a varying replacement, and I was wondering if anyone knew if that is possible in php or at least achievable by some means. For example, a string has two matches, then those matches will be replaced with two different variables. What I want are replacements to each be a unique id and I cannot figure out how this could possibly work or if php could even do this. For example if the match is 'a' and there is a sentence, 'put a smile on a person' then one 'a' will be unique id 98aksd00 and the other will be 09alkj08. I am retrieving my comments from a database so the preg replace is happening within

while ($row=mysql_fetch_assoc($query)){
//preg replace


If anyone could provide any insight into this, I would really appreciate it

© Stack Overflow or respective owner

Related posts about php