No cache version.

Caching disabled. Default setting for this page:enabled (code LNG204)
If the display is too slow, you can disable the user mode to view the cached version.

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]

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 13/09/2004, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/ast-rf-235.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.