Site Tools


webseite:php:xmlreader

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
webseite:php:xmlreader [2020/12/21 18:57] – created lunetikkwebseite:php:xmlreader [2020/12/21 20:05] (current) lunetikk
Line 12: Line 12:
 </code> </code>
  
 +Add to webserver
 <code php rssreader.php> <code php rssreader.php>
 <?php <?php
 //#### Read XML #### //#### Read XML ####
-$xml=simplexml_load_file("<YOURLOCALXML") or die("Error: Cannot create object");+$xml=simplexml_load_file("<YOURLOCALXML>") or die("Error: Cannot create object");
 $news = $xml->xpath('//item'); $news = $xml->xpath('//item');
 + 
 //#### Create Table #### //#### Create Table ####
 echo '<table style="font-size:14px">'; echo '<table style="font-size:14px">';
 + 
 //#### Foreach news article do #### //#### Foreach news article do ####
 foreach($news as $a) foreach($news as $a)
 { {
-//#### Title of news ####+        //#### Title of news ####
         echo '<tr><td colspan="2"><a href="' . $a->link . '">' . $a->title . '</a></td></tr>';         echo '<tr><td colspan="2"><a href="' . $a->link . '">' . $a->title . '</a></td></tr>';
         //#### Date of news ####         //#### Date of news ####
Line 39: Line 40:
 } }
 echo "</table>"; echo "</table>";
 + 
 //#### Function to limit text to 250 chars #### //#### Function to limit text to 250 chars ####
 //#### https://stackoverflow.com/questions/3161816/get-first-n-characters-of-a-string #### //#### https://stackoverflow.com/questions/3161816/get-first-n-characters-of-a-string ####
 function truncate($string,$length=250,$append="&hellip;") { function truncate($string,$length=250,$append="&hellip;") {
   $string = trim($string);   $string = trim($string);
 + 
   if(strlen($string) > $length) {   if(strlen($string) > $length) {
     $string = wordwrap($string, $length);     $string = wordwrap($string, $length);
Line 50: Line 51:
     $string = $string[0] . $append;     $string = $string[0] . $append;
   }   }
 + 
   return $string;   return $string;
 } }
 + 
 ?> ?>
 </code> </code>
webseite/php/xmlreader.1608573479.txt.gz · Last modified: 2020/12/21 18:57 by lunetikk