Getting the first URL of an image search result using the Google Image API in PHP

Do you know that php script (the class will be nice), who will get the URL of the first image as a result of google-api-image search? Thanks

Example.

<?php echo(geturl("searchterm")) ?> 
+4
source share
2 answers

You can easily do this with the Simple HTML DOM .

Note. See examples on your website for more details.

  • The HTML DOM parser, written in PHP5 +, allows you to control HTML in a very simple way!
  • Find tags on an HTML page with selectors like jQuery.
+2
source

I found a solution to get the first image from a Google Image result using Simple HTML DOM, as Sarfraz said.

Please check the code below. It currently works great for me.

 $search_keyword=str_replace(' ','+',$search_keyword); $newhtml =file_get_html("https://www.google.com/search?q=".$search_keyword."&tbm=isch"); $result_image_source = $newhtml->find('img', 0)->src; echo '<img src="'.$result_image_source.'">'; 
+3
source

Source: https://habr.com/ru/post/1312493/


All Articles