【问题标题】:Why preg_replace throws me a "Unknown modifier" error? [duplicate]为什么 preg_replace 向我抛出“未知修饰符”错误? [复制]
【发布时间】:2010-11-04 19:29:42
【问题描述】:

我不断收到此错误:

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

开:

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

我在 $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)

谁能告诉我我做错了什么?我被这个错误困扰太久了......

【问题讨论】:

    标签: php preg-replace modifier


    【解决方案1】:

    您正在使用正斜杠作为正则表达式模式分隔符,因此/&lt;title&gt;(.*)&lt;/title&gt;/Ui' 将不起作用(&lt;/title&gt; 有一个正斜杠)。

    您应该能够转义正斜杠或使用不包含在模式中的不同分隔符,例如

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

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

    【讨论】:

      猜你喜欢
      • 2011-02-01
      • 1970-01-01
      • 2021-11-11
      • 2015-05-09
      • 2013-10-04
      • 1970-01-01
      相关资源
      最近更新 更多