Code used to query the ranking position of a search engine in PHP

Source: Internet
Author: User
Using PHP to quickly query the ranking position of keywords in the search engine, the principle is very simple. The code is as follows:
/*
Query the ranking position of LANSJ in Google "Shenzhen Photography Studio", Lan Shi;
Lost63.com original
Search for the first 30 pages
*/
$ Page = 30; // Number of pages
$ Domain = "lansj.com"; // domain name
// $ Domain = "lost63.com ";
For ($ n = 0; $ n <= $ page; $ n ++ ){
$ Url = 'http: // www.google.cn/search? Hl = zh-CN & newwindow = 1 & q = % E6 % B7 % B1 % E5 % 9C % B3 % E6 % 91% E5 % BD % B1 % E5 % B7 % A5 % E4 % BD % 9C % E5 % AE % A4 & start = '. $ n. '0 & sa = N ';
// $ Url = 'http: // www.google.cn/search? Hl = zh-CN & lr = & newwindow = 1 & q = % E8 % BF % B7 % E5 % A4 % B1 % E8 % B7 % AF % E4 % B8 % 8A & start = '. $ n. '0 & sa = N ';
$ File = fopen ($ url, "r ");
While (! Feof ($ file ))
{
$ Result. = fgets ($ file, 9999 );
}
If (strpos ($ result, $ domain) = true ){
Echo 'found on the'. $ n. 'page
';
$ N = $ page;
} Else {
Echo 'nth. $ n. 'page not found
';
}
Fclose ($ file );
}
?>

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.