Looking for a way to increase counter on search/replace

I’m looking for a way to turn something like

[url=http://www.example.com/]Example link[/url] [url=http://www.example.com/]Example link2[/url]


<a href="http://www.example.com/" id="link1">Example link</a><a href="http://www.example.com/" id="link2">Example link2</a>

Is there a way to get the number of times preg_replace has replaced while it’s running?

It is not possible to find number of replaces using just preg_replace() function. But you can use preg_match_all() to get this number before applying preg_replace() to a string.

Sponsor our Newsletter | Privacy Policy | Terms of Service