This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| webseite:php:xmlreader [2020/12/21 18:58] – lunetikk | webseite:php:xmlreader [2020/12/21 20:05] (current) – lunetikk | ||
|---|---|---|---|
| Line 16: | Line 16: | ||
| <?php | <?php | ||
| //#### Read XML #### | //#### Read XML #### | ||
| - | $xml=simplexml_load_file("< | + | $xml=simplexml_load_file("< |
| $news = $xml-> | $news = $xml-> | ||
| + | |||
| //#### Create Table #### | //#### Create Table #### | ||
| echo '< | echo '< | ||
| + | |||
| //#### Foreach news article do #### | //#### Foreach news article do #### | ||
| foreach($news as $a) | foreach($news as $a) | ||
| { | { | ||
| - | //#### Title of news #### | + | |
| echo '< | echo '< | ||
| //#### Date of news #### | //#### Date of news #### | ||
| Line 40: | Line 40: | ||
| } | } | ||
| echo "</ | echo "</ | ||
| + | |||
| //#### Function to limit text to 250 chars #### | //#### Function to limit text to 250 chars #### | ||
| //#### https:// | //#### https:// | ||
| function truncate($string, | function truncate($string, | ||
| $string = trim($string); | $string = trim($string); | ||
| + | |||
| if(strlen($string) > $length) { | if(strlen($string) > $length) { | ||
| $string = wordwrap($string, | $string = wordwrap($string, | ||
| Line 51: | Line 51: | ||
| $string = $string[0] . $append; | $string = $string[0] . $append; | ||
| } | } | ||
| + | |||
| return $string; | return $string; | ||
| } | } | ||
| + | |||
| ?> | ?> | ||
| </ | </ | ||