【发布时间】:2015-08-01 16:09:49
【问题描述】:
我的字符串:
$string = "figno some text and another figno then last figno";
预期输出
1 some text and another 2 then last 3
我试过了:
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);
}
但它会一次替换所有出现的事件。我也试过preg_replace代替str_replace(),但输出相同
【问题讨论】:
标签: php regex string str-replace