一段PHP代碼有關問題

來源:互聯網
上載者:User
一段PHP代碼問題
PHP code
$url = "http://localhost/index.php/"."$string1";       $contents = file_get_contents($url);print_r($contents);    


PHP code
    $url = "http://localhost/index.php/"."$string1";       $contents = file_get_contents($url);//print_r($contents);              if((preg_match_all('/(<\/table>)/iUs', $contents, $match))){        $contents = $match[1][0];    }print_r($contents);



為什麼這2段代碼列印出的結果是一樣的啊,這個網頁是

...結構的啊,其他類似的能成功截取,就是這個網頁列印出的結果和沒截取是一樣的。。。

------解決方案--------------------
給出你的頁面內容才行呀,這樣子你讓人怎麼猜? 有問題的肯定就是在正則咯
------解決方案--------------------
第二段正則的地方輸出看下
PHP code
   if((preg_match_all('/(<\/table>)/iUs', $contents, $match))){         echo '333';                   //測試下是否正則匹配到        $contents = $match[1][0];        var_dump($contents);           //列印輸出看下    }
------解決方案--------------------
網頁是

...結構。而 preg_match_all('/(<\/table>)/iUs 等於是匹配全部結構。
又 $contents = $match[1][0]; //如果頁面僅有一個

... 結構。

那麼。跟file_get_contents()得出的結果不是一樣。是什嗎?
------解決方案--------------------
Regex有錯誤,改成:
preg_match_all('/

.*<\/table>/sU', $contents, $match)
------解決方案--------------------
preg_match('/<\/table>/is',$str,$m);
echo $m[0];
------解決方案--------------------
'">3,3'-二氯聯苯胺你入庫的資料沒有做轉義處理,所以出錯

mediumtext類型最大可存放 16M 字元,應該足夠了
------解決方案--------------------
$content=mysql_real_escape_string($contents[0]);
$SQL="INSERT INTO pagecontents (old_title,old_text) VALUES('{$string}','{$content}')";
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.