我需要的例子:
$input = "bar bar bar bar bar";
$result = preg_replace_callback('bar', 'foo', $input); // And there must be some way to limit preg_replace_callback so that it replaces only the first 2 (for example) matches of the expression
echo $result;
结果:foo foo bar bar bar
试过谷歌但没有找到任何东西。抱歉,我是 php 新手。