PHP get Baidu related search and original degree _php tutorial

Source: Internet
Author: User
PHP to get Baidu related search and original degree
Get the original degree is get_em_times, the higher the value the longer the text length the less original.
Search engine optimization for acquisition projects

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;

}

/**

* According to the space participle, get Baidu keyword exactly match the number 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_veriy ($content) {

if (Strpos ($content, "http://verify.baidu.com/")!==false) {

Baidu requires verification, exception

}

}

}

http://www.bkjia.com/PHPjc/486027.html www.bkjia.com true http://www.bkjia.com/PHPjc/486027.html techarticle PHP to get Baidu-related search and original degree to obtain the original degree is get_em_times, the higher the text length the longer the less original. Search engine Optimization class for acquisition projects 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.