My string:
$string = "figno some text and another figno then last figno";
Expected output
1 some text and another 2 then last 3
I tried so far:
preg_match_all("/figno/s",$string,$figmatch);
$figno=0;
for($i=0;$i<count($figmatch[0]);$i++){
$figno=$figno+1;
$string=str_replace($figmatch[0][$i],$figno,$string);
}
But it replaces all the occurrences at a time. I tried preg_replacein the place of str_replace() too but same output