Tema: Curl php
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/07/2013, 12:04
Avatar de xXn
xXn
 
Fecha de Ingreso: abril-2013
Ubicación: Buenos Aires
Mensajes: 41
Antigüedad: 11 años, 9 meses
Puntos: 2
Curl php

Hola, tengo un problema con este codigo y no me funciona, me gustaria que me dijeran que puede llegar a ser, ya que siempre me retorna 0 valores.

Lo que estoy queriendo hacer es mediante una palabra que me devuelva las imagenes de una busqueda de google.

Código PHP:
Ver original
  1. <?php
  2.     //get the word submitted from the form
  3.     $word = "universo";
  4.     $img_pattern = "#<img src=http\S* width=[0-9]* height=[0-9]*>#";
  5.     // validate the word
  6.  
  7.     if ($word != '') {
  8.         // initialise the session
  9.         $ch = curl_init();
  10.         // Set the URL
  11.         curl_setopt($ch, CURLOPT_URL, "http://images.google.com/images?gbv=1&hl=en&sa=1&q=".urlencode($word)."&btnG=Search+images");
  12.         // Return the output from the cURL session rather than displaying in the browser.
  13.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  14.         //Execute the session, returning the results to $curlout, and close.
  15.         $curlout = curl_exec($ch);
  16.         curl_close($ch);
  17.  
  18.         preg_match_all($img_pattern, $curlout, $img_tags);
  19.         //display the results - I'll leave the formatting to you
  20.         print("Resultado de la busqueda $word: ".sizeof($img_tags[0])."<br/>\n");
  21.  
  22.         foreach ($img_tags[0] as $val){
  23.              print(" ".$val."\n");
  24.         }
  25.    }
  26. ?>

Desde ya muchas gracias