php 为什么 preg_replace 会向我抛出“未知修饰符”错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1026387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why preg_replace throws me a "Unknown modifier" error?
提问by privateace
I keep getting this error:
我不断收到此错误:
Warning: preg_match() [function.preg-match]: Unknown modifier 't' in D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php on line 235
警告:preg_match() [function.preg-match]:D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php 中的未知修饰符 't' 在第 235 行
on:
在:
$PageContent = preg_replace($result->module_pregmatch, '', $PageContent);
I do a var_dump on the $result->module_pregmatch and I get the following:
我在 $result->module_pregmatch 上做了一个 var_dump,我得到以下信息:
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...
有人可以告诉我我做错了什么吗?我已经被这个错误困住太久了......
回答by Tom Haigh
You are using forward-slashes as your regex pattern delimeter, so /<title>(.*)</title>/Ui'will not work (</title>has a forward slash).
您使用正斜杠作为正则表达式模式分隔符,因此/<title>(.*)</title>/Ui'将不起作用(</title>有正斜杠)。
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)
or
或者
'~<title>(.*)</title>~Ui' //different delimiter

