2012-07-09 33 views
1
 $regex = '/\b'.$keyword.'\b/i'; // case insensitive match 
     if (preg_match($regex, $linkedin_html) == 0) 
     { 
      $this->_htmlValidationFailed++; 
      continue;     
     } 

表達當我使用此代碼..我得到錯誤未知的修飾詞「V」 ..未知的修飾詞「V」使用的preg_match()時,在正則表達式

請讓我知道什麼是問題,幫助我糾正。

+1

什麼是'$關鍵字'?可能它有一個'/ v',你需要'逃脫'它。 – 2012-07-09 11:41:28

+0

它是從互聯網上獲取的一些表達。 – 2012-07-09 11:42:20

+4

嘗試一下:'$ regex ='/ \ b'。 preg_quote($關鍵字)。 '\ b/i';' – 2012-07-09 11:43:33

回答

3
<?php 
$keyword = preg_quote($keyword, '/'); 

$regex = '/\b'.$keyword.'\b/i'; // case insensitive match 
if (preg_match($regex, $linkedin_html) == 0) 
{ 
    $this->_htmlValidationFailed++; 
    continue;     
} 
+0

謝謝berry ..但現在它說..警告:preg_match():編譯失敗:在偏移量#######處正則表達式太大。 – 2012-07-09 11:55:28

+0

@NarenKarthik嗯,我猜這意味着你的正則表達式太大了;)如果你只是測試關鍵字,也許一個循環與strstr比正則表達式更適合? – 2012-07-09 13:06:33

相關問題