有没有办法在达到某个索引时中断搜索preg_replace_callback
?PHP preg_replace_callback有没有办法打破搜索?
例如:
$content = preg_replace_callback('/'.preg_quote($_POST['query'],'#').'/i', function($matches) use($replacements,&$index) {
if ($index > count($replacements)) {
// I tried break; but doesn't work
}
if ($replacements[$index] != '') {
$matches[0] = $replacements[$index];
}
$index++;
return $matches[0];
}, $content);
@Kasramvd我已经在上面添加了一个示例代码。 – JohnnyQ