警告:preg_replace()函数。preg-replace]:未知修饰符' d '

时间:2022-05-02 22:26:21

I have a function that once in a while gives out an error:

我有一个函数偶尔会出错:

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'd'

警告:preg_replace()函数。preg-replace]:未知修饰符' d '

Most often it does not. I don't understand the pattern when it does and when it doesn't.

但大多数情况下不是这样的。我不理解它的模式,当它没有的时候。

I know almost nothing about regex, so any help would be greatly appreciated.

我对regex几乎一无所知,所以非常感谢您的帮助。

Here's the function:

的功能:

function textHighlight($haystack,$needle,$clr='yellow') {
    $haystack=preg_replace("/($needle)/i","<span style='background:$clr;'>\${1}</span>",$haystack);
    return $haystack;
}

Thank you.

谢谢你!

1 个解决方案

#1


3  

You may have a '/' character in the $needle variable. You can replace /../ with #...#

您可能在$指针变量中有一个'/'字符。你可以替换/ . ./ #……#

#1


3  

You may have a '/' character in the $needle variable. You can replace /../ with #...#

您可能在$指针变量中有一个'/'字符。你可以替换/ . ./ #……#