预替换错误
任何人都可以找到此错误的解决方案,
$str= trim(strip_tags($str));
$str = preg_replace("'<style[^>]*>.*</style>'siU",'',$str);
$patterns = array();
$patterns[0] = ' ';
$patterns[1] = ' ';
$patterns[2] = ' ';
$replacements = array();
$replacements[0] = '';
$replacements[1] = '';
$replacements[2] = ' ';
$str = preg_replace($patterns, $replacements, $str);
它显示此错误。
消息:preg_replace() [function.preg-replace]:没有结束分隔符“&”发现
-阿伦
Can anyone find the solution for this error,
$str= trim(strip_tags($str));
$str = preg_replace("'<style[^>]*>.*</style>'siU",'',$str);
$patterns = array();
$patterns[0] = ' ';
$patterns[1] = ' ';
$patterns[2] = ' ';
$replacements = array();
$replacements[0] = '';
$replacements[1] = '';
$replacements[2] = ' ';
$str = preg_replace($patterns, $replacements, $str);
It showing this error.
Message: preg_replace() [function.preg-replace]: No ending delimiter '&' found
-Arun
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
模式中的第一个字符被解释为分隔符,现在 PHP 认为您想要使用 &作为分隔符。在您的第一个正则表达式中,分隔符是
'
,顺便说一句。我猜你真正想要的不是' '
,而是'/ /'
(例如模式 2),现在/
是分隔符(它不是正则表达式本身的一部分)。顺便说一句,您的第一个正则表达式似乎也不正确,它可能应该是否则正则表达式可以匹配整个文档的第一个标签和最后一个标签。
The first character in your pattern is interpreted as a delimiter and right now PHP thinks you want to use & as a delimiter. In your first regex, the delimiter was
'
, BTW. I guess what you really want is not' '
, but'/ /'
(e.g. for pattern 2), now/
is the delimiter (it is not part of the regex itself). BTW, your first regex seems not correct either, it should probably beOtherwise the regex could match the first tag and the very last tag of the whole document.
您在错误代码中有答案,正则表达式需要分隔符才能工作。
您应该使用 str_replace 来代替
。
You have the anwser in the error code, regex needs delimiters to work.
And you should use str_replace for
.