Page 1 of 1

preg_replace help

Posted: Tue May 06, 2003 10:33 am
by boinnk
Is there a way to count the number of matches in preg_replace. Something like

Code: Select all

<?php

$out = preg_replace("a","a \\something","aaaaaaaaa");

?>
So that $out would contain "a1a2a3a4...".
Is this possible with using only regexp?

Posted: Tue May 06, 2003 11:20 am
by daven
not really. You can do a preg_match(), followed by preg_replace, however.

$out=preg_match("/a/","baaabaaabaaabaaa");
$end=preg_replace("/a/","/a replacement/","baaabaaabaaabaaa");