PHP gets Baidu-related searches and originality levels. 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. Search engine optimization for collection items classbidu {p PHP get Baidu-related search and originality level
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 (/
(((?!
).)*)
/, $ Content, $ result )){
If (preg_match_all (/).) *> (.*?) /, $ 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 (/(((?!).)*)/, $ 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
}
}
}
Get_em_times is used to obtain the original value. The higher the value, the longer the text length. Search engine optimization class baidu {p...