PHP to get Baidu related search and original degree
Get the original degree is get_em_times, the higher the value the longer the text length the less original.
Search engine optimization for acquisition projects
Class Baidu {
public static function Build_request_uri ($words) {
$words = UrlEncode (text::convert_encoding ($words, gbk,utf-8));
return/s?wd=. $words;
}
public static function Get_relate_search ($words) {
$content = Self::get_content ($words);
if (Preg_match ((?!).) *)/, $content, $result)) {
if (Preg_match_all (/).) *> (. *?) /, $result [1], $result)) return $result [2];
}
return FALSE;
}
/**
* According to the space participle, get Baidu keyword exactly match the number of times
* @param string $words
* @return int
*/
public static function Get_em_times ($words) {
$word = Explode (, $words);
$content = Self::get_content ($words);
Preg_match_all (/((?!).) *)/, $content, $result);
if (!isset ($result [1]) | | count ($result [1]) ==0)
return 0;
$word _table = Array_count_values ($result [1]);
$times = 0;
foreach ($word as $pice) {
if (Array_key_exists ($pice, $word _table)) $times + = $word _table[$pice];
}
return $times;
}
public static function Get_content ($words) {
static $loaded _contents = Array ();
if (!isset ($loaded _contents[$words])) {
$content = file_get_contents ("http://www.baidu.com". Self::build_request_uri ($words));
$content = text::convert_encoding ($content, UTF-8,GBK);
$loaded _contents[$words] = $content;
}
return $loaded _contents[$words];
}
function Check_veriy ($content) {
if (Strpos ($content, "http://verify.baidu.com/")!==false) {
Baidu requires verification, exception
}
}
}
http://www.bkjia.com/PHPjc/486027.html www.bkjia.com true http://www.bkjia.com/PHPjc/486027.html techarticle PHP to get Baidu-related search and original degree to obtain the original degree is get_em_times, the higher the text length the longer the less original. Search engine Optimization class for acquisition projects Baidu {p ...