为什么preg_replace会向我抛出“未知修饰符"?错误? [英] Why preg_replace throws me a "Unknown modifier" error?

查看:96
本文介绍了为什么preg_replace会向我抛出“未知修饰符"?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误:

警告:preg_match() [function.preg-match]:未知 修饰语"t"在 D:\ xampp \ htdocs \ administrator \ components \ com_smms \ functions \ plugin.php 在第235行

Warning: preg_match() [function.preg-match]: Unknown modifier 't' in D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php on line 235

上:

$PageContent = preg_replace($result->module_pregmatch, '', $PageContent);

我在$ result-> module_pregmatch上执行了var_dump,得到以下信息:

I do a var_dump on the $result->module_pregmatch and I get the following:

string '/<title>(.*)</title>/Ui' (length=23)

string '/<meta[^>]*name=["|\']description["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=77)

string '/<meta[^>]*name=["|\']keywords["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=74)

string '/<meta[^>]*name=["|\']author["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=72)

string '/<meta[^>]*name=["|\']copyright["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=75)

string '/<meta[^>]*name=["|\']robots["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=72)

string '/<meta[^>]*http=equiv=["|\']content-language["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=88)
string '/<meta[^>]*http-equiv=["|\']content-type["|\'][^>]*content=["|\'](.*)["|\']\s*\/>/Ui' (length=84)

string '/<link[^>]*href=["|\'](.*)["|\'][^>]*rel=["|\']shortcut[^>]*icon["|\'][^>]*type=["|\']image\/x-icon["|\']\s*\/>/Ui' (length=114)

string '/<link[^>]*href=["|\'](.*)["|\'][^>]*rel=["|\']alternate["|\'][^>]*type=["|\']application\/rss\+xml["|\'][^>]*title=["|\'](.*)["|\'][^>]\/>/Ui' (length=142)

string '/<link[^>]*href=["|\'](.*)["|\'][^>]*rel=["|\']alternate["|\'][^>]*type=["|\']application\/atom\+xml["|\'][^>]*title=["|\'](.*)["|\'][^>]\/>/Ui' (length=143)

有人可以告诉我我做错了什么吗?我被这个错误困扰了太久了...

Can someone please tell me what I'm doing wrong? I've been stuck on this error for way too long...

推荐答案

您将正斜杠用作正则表达式模式分隔符,因此/<title>(.*)</title>/Ui'将不起作用(</title>具有正斜杠).

You are using forward-slashes as your regex pattern delimeter, so /<title>(.*)</title>/Ui' will not work (</title> has a forward slash).

例如,您应该能够转义正斜杠或使用模式中未包含的其他定界符

You should be able to escape the forward slash or use a different delimiter that is not contained within the pattern, for example

'/<title>(.*)<\/title>/Ui' //(esacaping)

'~<title>(.*)</title>~Ui' //different delimiter

这篇关于为什么preg_replace会向我抛出“未知修饰符"?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆