Php function to search images from google and bing

The following php function will return an array(0-10) of image URLs.


<?php
/* Returns 10 image URLs array */
function images_search($se, $kw){
 $icount=0;
 $image =array();
 if($se=="Bing"){
 $imgs = 'http://www.bing.com/images/search?q='.urlencode(trim($kw));
 $imgs = file_get_contents($imgs);
 preg_match_all("/<span class="md_mu">(.*?)</span>/is", $imgs, $imgu, PREG_PATTERN_ORDER);

 shuffle($imgu[1]);
 $iv = array_values($imgu[1]);

 for($j=0; $j < count($iv);$j++)
 if(strpos($iv[$j],'"')>-1 || strpos($iv[$j],'""')>-1) continue;
 elseif(@fclose(@fopen($iv[$j], "r"))){  
 $image[$icount]=$iv[$j];
 $icount++;
 if($icount==10)
 break;
 }
 }else{
 $start=rand(0,9)*20+1;
 $imgs= 'http://images.google.com/images?gbv=2&hl=en&q='.urlencode(trim($kw)).'&sa=N&start='.$start.'&ndsp=30';
 $imgs = file_get_contents($imgs);
 preg_match_all("/x3dhttp:(.*?).jpg/is", $imgs, $imgu, PREG_PATTERN_ORDER);

 shuffle($imgu[1]);
 $iv = array_values($imgu[1]);

 for($j=0;$j<count($iv);$j++)
 if(strpos($iv[$j],'"')>-1 || strpos($iv[$j],'""')>-1) continue;
 elseif(@fclose(@fopen('http:'.$iv[$j].'.jpg', "r"))){  
 $image[$icount]='http:'.$iv[$j].'.jpg';
 $icount++;
 if($icount==10)
 break;     
 }
 }
 return $image;
}
?>

Use this function like this:

<?php

// Call function like

$google_images = images_search('Bing', 'doctors');

// or

$bing_images = images_search('Google', 'forex');

?>

Searched By:

catchy inurl:/guestbook html?page= (7), tramadol online overnight shipping inurl:/guestbook php?id= (6), inurl:/modules php?op= make signs free (6), addresses inurl:/guestbook pl (6), inurl:/posting php?mode= interracial babies (6), harris inurl:/vb 1/member php?u= (5), inurl:/register php? build (5), 10 minute trainer inurl:/gb asp (4), between inurl:/sign php (4), inurl:/index php?action=stats provided sudoku numbers (4), inurl:/register php centralise (4), including inurl:/guestbook php?newsid= (3), inurl:/modules php?op= doing business in australia (3), inurl:/book php alligatoring (3), inurl:/register php outline (3), 1000 games shooting inurl:/add php (3), inurl:/index php nba stats news (3), munchen inurl:/register intext:upcoming intext:published intext:submit -inurl: php (3), inurl:/write asp agile (3), long inurl:/board_list php?board index= (2)

Related posts:

  1. Alternate to php copy, move function
  2. Google Hot Trend Auto Blog Poster
  3. Automatic Free Backlinks Easy PHP Script
  4. File transferring, uploading from one server to other server using php
  5. Creating Windows Standard Dynamic Link Library (DLL) to Use with VB6 and Meta Trader (MT4)

Leave a Reply