Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_replace_callback():未知修饰符'/';_Php - Fatal编程技术网

Php preg_replace_callback():未知修饰符'/';

Php preg_replace_callback():未知修饰符'/';,php,Php,我需要搜索并突出显示单词 我的判决是 Please see our Author Guide for more information: http://digital-library.theiet.org/journals/author-guide. you will be contacted shortly asking you to take a decision and sign either a copyright or Open Access licence form. 我的代码 f

我需要搜索并突出显示单词

我的判决是

Please see our Author Guide for more information: http://digital-library.theiet.org/journals/author-guide.
you will be contacted shortly asking you to take a decision and sign either a copyright or Open Access licence form.
我的代码

function find_highlight_word($word) {
        $text = preg_replace_callback($word, function($matches) use (&$counter) {

            $counter++;
            return '<b class="search_mark highlighted" id="matched_' . $counter . '">'
                    . substr($matches[0], 0, strlen($matches[0]))
                    . '</b>';
        }, $text);

        return $text;
}
$word = '//';
$word = '/' . preg_quote($word) . '/i';
$this->find_highlight_word($word);
函数查找突出显示单词($word){
$text=preg_replace_回调($word,function($matches)use(&$counter){
$counter++;
返回“”
.substr($matches[0],0,strlen($matches[0]))
. '';
}美元文本);
返回$text;
}
$word='/';
$word='/'。preg_quote($word)。'/我;
$this->find_highlight_word($word);

当我用“/”搜索时,此时显示php错误。

您正确地尝试对字符串进行预引号,但您没有告诉它分隔符是什么,因此字符串中的
/
导致了问题。将使用的分隔符作为第二个参数传递,以便也可以对其进行转义:

$word = '/' . preg_quote($string, '/') . '/i';

您正正确地尝试对字符串进行预引号,但没有告诉它分隔符是什么,因此字符串中的
/
导致了问题。将使用的分隔符作为第二个参数传递,以便也可以对其进行转义:

$word = '/' . preg_quote($string, '/') . '/i';

好的,您的函数接受参数
$word
,但您似乎使用了
$string
。@McEmperon是的,我更新了好的,您的函数接受参数
$word
,但您似乎使用了
$string
。@McEmperon是的,我更新了