PHP obtains Baidu-related search and originality. The original degree is get_em_times. the higher the value, the longer the text length, and the less original the text. The search engine optimization classbidu {publicstaticfunctionbuild_request_uri ($ words) {$ words = urlencode (Text: conv
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 \>).) *) \ <\/div \>/', $ content, $ result )){
If (preg_match_all ('/\).) * \> (.*?) \ <\/A \>/', $ result [1], $ result) return $ result [2];
}
Return FALSE;
}
/**
* Use space-based word segmentation to obtain full match of Baidu keywordsNumber 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 ('/\ (((?! \ </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
}
}
}