Ver Mensaje Individual
  #5 (permalink)  
Antiguo 20/11/2011, 07:04
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: Cómo puedo hacer un feed automático

muy simple, de la misma manera que cuando generas una tabla desde una bd
Código PHP:
Ver original
  1. echo "<table";
  2. while($row = mysql_fetch_array($req))
  3.             {
  4.                $id = $row['id'];
  5.                $fecha = $row['fecha'];
  6.                $nombre = $row['nombre'];
  7.  
  8.  
  9. echo"<tr><td>$id</td><td>$fecha</td><td>$nombre</td></tr>";
  10.     }
  11. echo "</table>";

haces lo mismo, pero generando las entradas del xml, algo básico para rss 2.0 sería

feed.rss.php

Código PHP:
Ver original
  1. <?php
  2. ini_set('short_open_tag',0);
  3. ?>
  4. <?xml version="1.0"?>
  5. <rss version="2.0">
  6.    <channel>
  7.       <title>Liftoff News</title>
  8.       <link>http://liftoff.msfc.nasa.gov/</link>
  9.       <description>Liftoff to Space Exploration.</description>
  10.       <language>en-us</language>
  11.       <pubDate>Tue, 10 Jun 2003 04:00:00 GMT</pubDate>
  12.  
  13.       <lastBuildDate>Tue, 10 Jun 2003 09:41:01 GMT</lastBuildDate>
  14.       <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  15.       <generator>Weblog Editor 2.0</generator>
  16.       <managingEditor>[email protected]</managingEditor>
  17.       <webMaster>[email protected]</webMaster>
  18.  
  19. <?php
  20.  
  21. // aqui la consulta y el loop para recuperar, pero en lugar de generar una fila...
  22.  
  23. echo"
  24.      <item>
  25.         <title>$titulo</title>
  26.         <link>$link</link>
  27.         <description>";
  28.  
  29. echo htmlentities($description);
  30.  
  31. echo "</description>
  32.         <pubDate>$pubdate</pubDate>
  33.         <guid>$guid</guid>
  34.  
  35.      </item>
  36. ";
  37.  
  38. ?>
  39.  
  40.    </channel>
  41. </rss>

Saludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.