Search code examples
phpfile-get-contents

Using the file_get_contents function, I want to get first few google results, instead of all


I've used the file_get_contents to get the google results of a string and display to the web page.

$url = "http://www.google.com/search?q=".$str;

$result = file_get_contents($url);

echo $result;

But is it possible to display only the first few results, say 5, instead of all the results ?


Solution

  • To limit the number of Google search results, add the parameter &num=5 to your Google query.

    Compare

    https://www.google.co.uk/search?site=&source=hp&q=foo

    https://www.google.co.uk/search?site=&source=hp&q=foo&num=5