2017-02-24 9 views
-1

我不明白我的代碼出現問題。代碼顯示我的錯誤信息正則表達式爲http-equiv =「刷新」元標記

PHP Parse error: syntax error, unexpected ')' in /home/masudtoo/public_html/autocreate/index.php on line 151

問題是從這一代碼來對行151:

$google_meta_regex = '/\\<meta http-equiv.+?refresh.+?(http:\\/\\/[^\\'^\\"^\\>]+?)('){0,1}(\\"){0,1}\\>/i'; 

全碼:

if (strpos($page, '<meta http-equiv')) { 
    // Follow the Meta redirect 
    $google_meta_regex = '/\\<meta http-equiv.+?refresh.+?(http:\\/\\/[^\\'^\\"^\\>]+?)('){0,1}(\\"){0,1}\\>/i'; 
    preg_match($google_meta_regex,$page,$m); 
    $curl_url = $m[1]; 
    $curl_url = str_replace('&amp;', '&', $curl_url); 

    $headers[] = "Cookie: X=abc; GoogleAccountsLocale_session=en; TZ=-330"; 
    $headers[] = "Content-Type: application/x-www-form-urlencoded"; 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 

     curl_setopt($ch, CURLOPT_URL, $curl_url); 
    curl_setopt($ch, CURLOPT_POST, 0); 
     $page = curl_exec($ch); 
} 

curl_close($ch); 
+0

[使用一個真正的解析器,不是正則表達式,爲這個(http://stackoverflow.com/questions/3577641/how-do-you-parse -and-process-html-xml-in-php) – Quentin

回答

0

的問題是,你忘了逃跑一個報價',它與字符串的一個關閉字符串衝突。因此,下面正則表達式/代碼應該工作:

$google_meta_regex = '/\\<meta\\shttp-equiv.+?refresh.+?(http\\:\\/\\/[^\\\'^\\"^\\>]+?)(\\\'){0,1}(\\"){0,1}\\>/i'; 
+0

感謝回覆但不工作,同樣的錯誤。 –