PHP retrieves Baidu-related searches and originality

Source: Internet
Author: User

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

}

}

}

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.