2009-06-22 62 views
12

我不斷收到此錯誤:爲什麼preg_replace會引發「未知修飾符」錯誤?

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); 

我做對了的var_dump $ result-> module_pregmatch,我得到以下幾點:

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) 

人請告訴我我做錯了什麼?我一直卡在這個錯誤的方式太長...

回答

37

您正在使用正斜槓作爲您的正則表達式模式的分隔符,所以/<title>(.*)</title>/Ui'將無法​​正常工作(</title>有一個正斜槓)。

您應該能夠逃脫斜線或使用未包含在圖案內的不同分隔符,例如

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

'~<title>(.*)</title>~Ui' //different delimiter 
相關問題