Return to Snippet

Revision: 25405
at March 30, 2010 07:36 by ginoplusio

Initial Code
function getGoogleImg($k) {
	$url = "";
	$web_page = file_get_contents( str_replace("##query##",urlencode($k), $url ));

	$tieni = stristr($web_page,"dyn.setResults(");
	$tieni = str_replace( "dyn.setResults(","", str_replace(stristr($tieni,");"),"",$tieni) );
	$tieni = str_replace("[]","",$tieni);
	$m = preg_split("/[\[\]]/",$tieni);
	$x = array();
	for($i=0;$i<count($m);$i++) {
		$m[$i] = str_replace("/imgres?imgurl\\x3d","",$m[$i]);
		$m[$i] = str_replace(stristr($m[$i],"\\x26imgrefurl"),"",$m[$i]);
		$m[$i] = preg_replace("/^\"/i","",$m[$i]);
		$m[$i] = preg_replace("/^,/i","",$m[$i]);
		if ($m[$i]!="") array_push($x,$m[$i]);
	return $x;

Initial URL

Initial Description
This simply php function will retrieve the links of the images from Google Images searched with a keyword. The function just calls and parse the html to find the url of the images, in this case the urls are stored in the javascript, so the parsing doesn’t use any html tag to find data. It builds an array of urls and return it.

Initial Title
How to get images from Google images with PHP

Initial Tags
google, images, web, service

Initial Language