Ver Mensaje Individual
  #3 (permalink)  
Antiguo 13/08/2012, 06:30
Avatar de topo_bionico
topo_bionico
 
Fecha de Ingreso: junio-2012
Mensajes: 89
Antigüedad: 12 años, 7 meses
Puntos: 20
Respuesta: obtener la url de una imagen de otro sitio web

Cita:
Iniciado por andresdzphp Ver Mensaje
Ya tienes el código para sacar una imagen de otro sitio y meterlo a la clase no es muy complicado. La pregunta es de donde quieres sacar la imagen? Te dejo un ejemplo rápido pero no funcional 100% hasta no saber el origen de la imagen. (Dejo las líneas que faltan por completar comentadas)

Código PHP:
Ver original
  1. <?php
  2. class RssReader
  3. {
  4.     var $url;
  5.     var $data;
  6.     function RssReader($url) {
  7.         $this->url;
  8.         $this->data = implode("", file($url));
  9.     }
  10.     function get_items() {
  11.         preg_match_all("/<item .*>.*<\/item>/xsmUi", $this->data, $matches);
  12.         $items = array();
  13.         foreach ($matches[0] as $match) {
  14.             $items[] = new RssItem($match);
  15.         }
  16.         return $items;
  17.     }
  18. }
  19. class RssItem
  20. {
  21.     var $title, $url, $description, $imgs;
  22.     function RssItem($xml) {
  23.         $this->populate($xml);
  24.     }
  25.     function populate($xml) {
  26.         preg_match("/<title> (.*) <\/title>/xsmUi", $xml, $matches);
  27.         $this->title = $matches[1];
  28.         preg_match("/<link> (.*) <\/link>/xsmUi", $xml, $matches);
  29.         $this->url = $matches[1];
  30. /***********************************************************************/
  31.         $doc = new DOMDocument();
  32.         $doc->loadHTML(file_get_contents($this->url)); //debe ir la url en donde esta la imagen
  33.         $xpath = new DOMXPath($doc);
  34.         $this->imgs = $xpath->query('//td[@id="img_primary"]/a/img')->item(0)->getAttribute('src'); //varia según en donde esté la imagen
  35. /***********************************************************************/
  36.         preg_match("/<description> (.*) <\/description>/xsmUi", $xml, $matches);
  37.         $this->description = $matches[1];
  38.     }
  39.     function get_title() {
  40.         return iconv('UTF-8', 'ISO-8859-1', $this->title);
  41.     }
  42.     function get_url() {
  43.         return iconv('UTF-8', 'ISO-8859-1', $this->url);
  44.     }
  45.     function get_img() {
  46.         return iconv('UTF-8', 'ISO-8859-1', $this->imgs);
  47.     }
  48.     function get_description() {
  49.         return iconv('UTF-8', 'ISO-8859-1', $this->description);
  50.     }
  51. }
  52.  
  53. $rss = new RssReader("http://www.cinemundo.cl/cines/roble/feed/");
  54.  
  55. foreach ($rss->get_items() as $item) {
  56.     printf('<div><img src="%s" /><a href="%s">%s</a><br />%s<br /><br />',
  57.     html_entity_decode($item->get_img()), html_entity_decode($item->get_url()),
  58.     html_entity_decode($item->get_description()), html_entity_decode($item->get_title()));
  59.     printf('</div>');
  60. }

PD: No me gustan las clases que usan expresiones regulares, quedaría mejor todo con DOM.

Saludos.
Me parece que lo que quiere es obtener los enlaces de las imágenes del feed para poder mostrarlas.
Si es así, hay que pasarle a la función que extrae el url de las imágenes el contenido de la etiqueta <description>, porque el feed esta en formato XML y esa es la etiqueta que contiene el post.