Site Tools


webseite:php:xmlreader

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
webseite:php:xmlreader [2020/12/21 18:58] lunetikkwebseite:php:xmlreader [2020/12/21 19:39] lunetikk
Line 14: Line 14:
 Add to webserver Add to webserver
 <code php rssreader.php> <code php rssreader.php>
 +<?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 40: Line 41:
 } }
 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 51: Line 52:
     $string = $string[0] . $append;     $string = $string[0] . $append;
   }   }
 + 
   return $string;   return $string;
 } }
 + 
 ?> ?>
 </code> </code>
webseite/php/xmlreader.txt · Last modified: 2020/12/21 20:05 by lunetikk