PHP retrieves Baidu-related searches and originality
The Obtained Degree of originality is get_em_times. The higher the value, the longer the text length.
Search engine optimization for collection items
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 (/<div id = "rs"> (((?! </Div>).) *) </div>/, $ content, $ result )){
If (preg_match_all (/<a (?!> ).) *> (.*?) </A>/, $ result [1], $ result) return $ result [2];
}
Return FALSE;
}
/**
* The number of times that Baidu keywords fully match <em> </em> are obtained based on space word segmentation.
* @ Param string $ words
* @ Return int
*/
Public static function get_em_times ($ words ){
$ Word = explode (, $ words );
$ Content = self: get_content ($ words );
Preg_match_all (/<em> (((?! </Em>).) *) </em>/, $ 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_policy ($ content ){
If (strpos ($ content, "http://verify.baidu.com /")! = FALSE ){
// Baidu requires verification, exception
}
}
}