簡體   English   中英

PHP,獲取網頁內容單詞

[英]PHP, get web-page content words

我正在建立一個網站,推薦其他好的網站。

因此,我使用爬網系統收集了很多網站。

現在,我試圖通過使用PHP來區分網站是否有好詞。

$page_content = file_get_contents($url);
$bad_word = 'damn';

if(strstr($page_content, $bad_word)):
    $result = 'YES';
else:
    $result = 'NO';
endif;

我的代碼是這樣的。

我使用Codeigniter並收到此消息。

An Error Was Encountered

Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.

它在某些網站上可以正常工作,但在其他網站上則無法工作。

還有其他檢索網站內容的方法嗎?

昨天我已經回答了類似的帖子,但現在又重復了:)您可以使用preg_match()獲得更好的結果。 preg_match不只包含正則表達式。 它可以完全滿足您的需求。 即:

if (preg_match("/bad-word/i", "page written content of many good and bad words")) {
    $result = 'YES';

} else {
     $result = 'NO';

}

“ i”表示區分大小寫,有關更多示例,請查看PHP手冊: http : //php.net/manual/zh/function.preg-match.php

有些網站需要通過cURL提交表單。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM