-2

I am trying hard to find a way to get the number of Google search results using PHP? I have search Google and stackoverflow but have not found anything suitable.

I want to know how can I do this using PHP.

Martin Evans
  • 45,791
  • 17
  • 81
  • 97
poretu terdi
  • 89
  • 1
  • 7

2 Answers2

1

When not using APIs:

$content = file_get_contents('https://www.google.com/search?q=test');
preg_match('/<div class="sd" id="resultStats">.*?([0-9\.\,]+).*?<\/div>/', $content, $matches);

var_dump($matches[1]);

Although i would advise against this way of (automated) queries.

Ronald Swets
  • 1,669
  • 10
  • 16
0

you can parse google search page. in the return page, there has number of google search result . such as, when we search stackoverflow in google search box, these text will appear under google search box: About 34,800,000 results (0.79 seconds)

潘兴龙
  • 3
  • 3
  • Actually, The Google Web Search API is officially deprecated as of November 1, 2010. – 潘兴龙 Dec 20 '16 at 10:28
  • Actually, [The Google Web Search API is officially deprecated as of November 1, 2010](https://developers.google.com/web-search/docs/ ). so the way offer by Brijesh Khatri may fail. – 潘兴龙 Dec 20 '16 at 10:30