Why preg_replace throws me a “Unknown modifier” error? [duplicate]

房东的猫 提交于 2019-11-26 14:29:11

问题


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

on:

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

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...


回答1:


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)

or

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


来源:https://stackoverflow.com/questions/1026387/why-preg-replace-throws-me-a-unknown-modifier-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!