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');

?>

There are cases when a php developers need to insert mysql data with strings which containing single or double quotes. Mysql  gives error or will not save data if we do not properly escape the string formation characters. To escape these characters php have a function {mysql_real_escape_string()}. This function can be used to format the mysql strings with escaping. e.g.

<?php

$escaped_mystring = mysql_real_escape_string($mystring);

?>

Now if you run the query after escaping it will save the string wit out any error.

Courage to live the Life

Be simple but look stylish, be tough but look soft, be tensed but look cool, be a beginner but look winner. Thats the way of life. Life has no pause buttons! Dreams have no expiry date! Time has not holiday! So don’t waste a single moment in your life! Live it….!