preg_replace替换子字符串php中的数字

preg_replace替换子字符串php中的数字,php,regex,preg-replace,Php,Regex,Preg Replace,我有一根绳子 $string = 'id="0000001" did="659" interval="2" media.jpg' 我想用0替换间隔标记中的2(值是动态的0到1000)。我怎么做 我尝试了以下代码,但它替换了所有代码 $returnValue = preg_replace('/\\d+/', '0', $string, -1, $count); $returnValue=preg_replace('/(?$returnValue=preg_replace('/(?这是另一种不使

我有一根绳子

$string = 'id="0000001" did="659" interval="2" media.jpg'
我想用0替换间隔标记中的2(值是动态的0到1000)。我怎么做

我尝试了以下代码,但它替换了所有代码

$returnValue = preg_replace('/\\d+/', '0', $string, -1, $count);

$returnValue=preg_replace('/(?
$returnValue=preg_replace('/(?这是另一种不使用lookback断言的方法,但是使用lookback要酷得多

preg_replace('/(interval=")(\d+)/','${1}0', $string, -1, $count);

这是不使用lookback断言的另一种方法,但是使用lookback要酷得多

preg_replace('/(interval=")(\d+)/','${1}0', $string, -1, $count);
@普密沙赫使用
(?@BhumiShah
$re=“/(?@BhumiShah使用
)(?@BhumiShah
$re=“/(?@BhumiShah
)?