Witam mam problem może mi ktoś napisać taką funkcje? mam zmienna $bez_niczego
i niech funkcja wpisuje w google image zawartosc zmiennej $bez_niczego np kot i wkleja pierwszy obrazek na stronie mam taka klase ale coś nie działa

  1. class getGoogleImage
  2. {
  3. public $img = null;
  4.  
  5. public function __construct($query, $start = 0, $max_w = false, $max_h = false)
  6. {
  7. $link = "http://www.google.pl/search?num=20&hl=pl&site=imghp&tbm=isch&source=hp&q={$query}&btnG=Wyszukiwanie+obrazem&gbv=1&sei=hgORULnBBsyO4gTNLw&start=$start";
  8.  
  9. $source = $this->getSource($link);
  10.  
  11. if(!$source)
  12. die('Nie mozna pobrac zrodla strony!');
  13.  
  14. $explode = explode('<td style="width:25%;word-wrap:break-word">', $source);
  15.  
  16. foreach($explode as $e)
  17. {
  18. $img = explode('<a href="/imgres?imgurl=', $e);
  19.  
  20. if(count($img) > 1)
  21. {
  22. $img = explode('&amp;', $img[1]);
  23.  
  24. if($max_h && $max_w)
  25. {
  26. $dims = explode(' &times; ', $e);
  27. $width = explode('<br>', $dims[0]);
  28. $width = $width[count($width) - 1];
  29.  
  30. $height = explode(' - ', $dims[1]);
  31. $height = $height[0];
  32.  
  33. if(intval($width) <= $max_w && intval($height) <= $max_h)
  34. {
  35. $this->img = $img[0];
  36. break;
  37. }
  38. }
  39. else
  40. {
  41. $this->img = $img[0];
  42. break;
  43. }
  44. }
  45. }
  46. if($this->img == NULL)
  47. {
  48. $this::__construct($query, $start + 20, $max_w, $max_h);
  49. }
  50. }
  51.  
  52. public function getImage()
  53. { return $this->img; }
  54.  
  55. public function getSource($URL)
  56. {
  57. $c = curl_init();
  58. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  59. curl_setopt($c, CURLOPT_URL, $URL);
  60. $s = curl_exec($c);
  61. curl_close($c);
  62.  
  63. if ($s)
  64. return $s;
  65. else
  66. return false;
  67. }
  68. }

użycie
  1. $obrazek = new getGoogleImage('kot', 0, 400, 400);
  2. echo $obrazek->getImage();