PHP retrieval of Baidu-related search and originality _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.