Geen cache-versie.

Caching uitgeschakeld. Standaardinstelling voor deze pagina:ingeschakeld (code LNG204)
Als het scherm te langzaam is, kunt u de gebruikersmodus uitschakelen om de cacheversie te bekijken.

Vous devez être membre et vous identifier pour publier un article.
Les visiteurs peuvent toutefois commenter chaque article par une réponse.

Réaliser un RSS depuis n'importe quelle page

Astuces de l’Infobrol (Développement)Article publié le 26/04/2005 10:26:09


  1. ‹?php
  2.  
  3. // Screen scraping your way into RSS
  4. // Example script, by Dennis Pallett
  5. // http://www.phpit.net/tutorials/screenscrap-rss
  6.  
  7. // Get page
  8. $url = "http://www.phpit.net/";
  9. $data = implode("", file($url));
  10.  
  11. // Get content items
  12. preg_match_all ("/‹div class=\"contentitem\"›([^`]*?)‹\/div›/", $data, $matches);
  13.  
  14. // Begin feed
  15. header ("Content-Type: text/xml; charset=ISO-8859-1");
  16. echo "‹?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?›\n";
  17. ?›
  18. ‹rss version="2.0"
  19. xmlns:dc="http://purl.org/dc/elements/1.1/"
  20. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  21. xmlns:admin="http://webns.net/mvcb/"
  22. xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"›
  23. ‹channel›
  24. ‹title›PHPit Latest Content‹/title›
  25. ‹description›The latest content from PHPit (http://www.phpit.net), screen scraped!‹/description›
  26. ‹link›http://www.phpit.net‹/link›
  27. ‹language›en-us‹/language›
  28.  
  29.  
  30. ‹?
  31. // Loop through each content item
  32. foreach ($matches[0] as $match) {
  33. // First, get title
  34. preg_match ("/\"›([^`]*?)‹\/a›‹\/h3›/", $match, $temp);
  35. $title = $temp['1'];
  36. $title = strip_tags($title);
  37. $title = trim($title);
  38.  
  39. // Second, get url
  40. preg_match ("/‹a href=\"([^`]*?)\"›/", $match, $temp);
  41. $url = $temp['1'];
  42. $url = trim($url);
  43.  
  44. // Third, get text
  45. preg_match ("/‹p›([^`]*?)‹span class=\"byline\"›/", $match, $temp);
  46. $text = $temp['1'];
  47. $text = trim($text);
  48.  
  49. // Fourth, and finally, get author
  50. preg_match ("/‹span class=\"byline\"›By ([^`]*?)‹\/span›/", $match, $temp);
  51. $author = $temp['1'];
  52. $author = trim($author);
  53.  
  54. // Echo RSS XML
  55. echo "‹item›\n";
  56. echo "\t\t\t‹title›" . strip_tags($title) . "‹/title›\n";
  57. echo "\t\t\t‹link›http://www.phpit.net" . strip_tags($url) . "‹/link›\n";
  58. echo "\t\t\t‹description›" . strip_tags($text) . "‹/description›\n";
  59. echo "\t\t\t‹content:encoded›‹![CDATA[ \n";
  60. echo $text . "\n";
  61. echo " ]]›‹/content:encoded›\n";
  62. echo "\t\t\t‹dc:creator›" . strip_tags($author) . "‹/dc:creator›\n";
  63. echo "\t\t‹/item›\n";
  64. }
  65. ?›
  66. ‹/channel›
  67. ‹/rss›


Avatar :: reboot Un article de reboot

Source : www.phpit.net


Commenter l'article

Commentaires


09/05/2005 22:34:28

Sinon, il y a l'article de Snspy qui est plus facile pour afficher les RSS (il suffit d'installer le soft): cf ast237

- Lea72 -

Sélection, tri et recherche d'articles
FILTRER :
TRIER :1er critère : 2e critère :
CHERCHER : Dans les titres Dans le contenu


[Afficher les liens en fonction des critères du formulaire ci-dessus]

Nederlandse vertaling

U hebt gevraagd om deze site in het Nederlands te bezoeken. Voor nu wordt alleen de interface vertaald, maar nog niet alle inhoud.

Als je me wilt helpen met vertalingen, is je bijdrage welkom. Het enige dat u hoeft te doen, is u op de site registreren en mij een bericht sturen waarin u wordt gevraagd om u toe te voegen aan de groep vertalers, zodat u de gewenste pagina's kunt vertalen. Een link onderaan elke vertaalde pagina geeft aan dat u de vertaler bent en heeft een link naar uw profiel.

Bij voorbaat dank.

Document heeft de 13/09/2004 gemaakt, de laatste keer de 26/10/2018 gewijzigd
Bron van het afgedrukte document:https://www.gaudry.be/nl/ast-rf-235.html

De infobrol is een persoonlijke site waarvan de inhoud uitsluitend mijn verantwoordelijkheid is. De tekst is beschikbaar onder CreativeCommons-licentie (BY-NC-SA). Meer info op de gebruiksvoorwaarden en de auteur.