Reputation: 11061
How would I use preg_replace to replace:
Some text is [[1]] and some is [[2]] bla bla...
into this:
Some text is 1.____________ and some is 2.____________ bla bla...
I have this regex that finds me the right occurrences, but I don't know how to add replacement digits into the result?
preg_replace('(\[\[\d\]\])', '_______', $subject);
This gets me this result:
Some text is ____________ and some is ____________ bla bla...
Upvotes: 3
Views: 52
Reputation: 107357
You need to use a capture group and a reference to it :
preg_replace('~\[\[(\d)\]\]~', '$1._______', $subject);
Upvotes: 4