2012-06-11 171 views
0

我正在建一个网站,推荐其他好网站。PHP,获取网页内容文字

因此,我通过使用抓取系统收集了很多网站。

现在,我想通过使用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. 

它工作正常,某些网站,但它不适用于其他网站。

有没有其他的方式来检索网站的内容?

+2

你需要给一些拒收工作例如去帮助别人找出原因。 – Tinyfool

+0

听起来像是一种很慢的方式来做到这一点,如果你每次检查单词(并逐个检查)。 – nico

+0

我希望您知道您的“抓取工具”最有可能将大多数新闻和社交网站标记为“不良”。 –

回答

1

我已经在昨天回复了类似的帖子,但这里又是一次:)您可以使用preg_match()来获得更好的结果。 preg_match不仅仅包含正则表达式。它可以做到你所需要的。即:

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

} else { 
    $result = 'NO'; 

} 

“我”的意思区分大小写,检查PHP手册,了解更多的例子:http://php.net/manual/en/function.preg-match.php

+0

我的意思是不区分大小写 – jco

0

一些网站需要通过cURL提交表单。