Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/12/2008, 08:05
Suyta
(Desactivado)
 
Fecha de Ingreso: septiembre-2004
Mensajes: 360
Antigüedad: 20 años, 5 meses
Puntos: 1
CURL captura de imágenes

Hola
Quiero mostrar información desde IMDB. Antes no tenía problemas para mostrar las imágenes pero ahora parece que han hecho algunos cambios y tengo que usar CURL.

Código PHP:
<?php
ob_start
();
if(isset(
$_REQUEST['t'])) {
$title=$_REQUEST['t'];
}
else
{
  
$title="tt0918927";
}

$default="http://www.imdb.com/title/$title";

$strfile_get_contents($default);
preg_match_all('/\<h5\>Plot\:([\w\W]*?)tn15more/',$str,$match);
  for (
$b=0$bcount($match[0]); $b++) {
  
$plot=$match[$b][$b];
  
$plot=str_replace('<a class="'""$plot);
  
$plot=str_replace('<h5>'"<h2>"$plot);
  
$plot=str_replace('</h5>'"</h2>"$plot);
  
$plot=str_replace("tn15more"""$plot);

}
//echo $plot;
//echo "<h2>Recommendations:</h2>";

preg_match_all('/also recommends:([\w\W]*?)IMDb User /',$str,$match1);
  for (
$c=0$ccount($match1[0]); $c++) {
  
$img=$match1[$c][$c];
  
$img=str_replace('also recommends:'""$img);
  
$img=str_replace('IMDb User '""$img);
  
$img=preg_replace('|<\/*a.*?>|si'''$img);


}
preg_match_all('/\<tr\>([\w\W]*?)rating/',$img,$found1);
for (
$e=0$ecount($found1[0]); $e++) {

  
$linkon=$found1[$e][$e];
preg_match_all('/\<td([\w\W]*?)\<\/td\>/',$linkon,$found5);
  for (
$f=0$fcount($found5[0]); $f++) {
  
$linkon5=$found5[0][$f];

  
$linkon5=str_replace('<td>'""$linkon5);
  
$linkon5=str_replace('</td>'""$linkon5);

  
preg_match_all('/<img([\w\W]*?)>/',$img,$found);

  
$linko=$found[0][$f];
  
preg_match_all('/src([\w\W]*?)jpg/',$linko,$found25);

  for (
$h=0$hcount($found25[0]); $h++) {
  
$src=$found25[0][$h];
  
$found25[0][$h]=str_replace('src="'''$found25[0][$h]);

  
//echo "<p>".$linkon5."</p>"; //title
  //echo "<p>".$linko."</p>";   //full image link with tags 

$ch curl_init($found25[0][$h]);
if (! 
$ch) {
die( 
"Cannot allocate a new PHP-CURL handle" );
}

// We’ll be returning this transfer, and the data is binary
// so we don’t want to NULL terminate
curl_setopt($chCURLOPT_RETURNTRANSFER1);
curl_setopt($chCURLOPT_BINARYTRANSFER1);

// Grab the jpg and save the contents in the $data variable
$found25[0][$h] = curl_exec($ch);

// close the connection
curl_close($ch);

// Set the header to type image/jpeg, since that’s what we’re
// displaying
header("Content-type: image/jpeg");

// Output the image
print $found25[0][$h];
}
}
}
?>
Tengo 2 problemas:
1 - sólo muestra la 1ra. imagen... no logro recorrer el array.
2 - hay alguna forma de imprimir esos echo (ahora comentados) que están antes del header ?
Si alguien tiene 1 minuto, gracias !