ตัวอย่างการอ่านไฟล์ rss feed ด้วย simplexml_load_file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<?php header('Content-Type: text/html; charset=UTF-8'); // The file test.xml contains an XML document with a root element // and at least an element /[root]/title. $xml = simplexml_load_file('https://seenual.com/?feed=rss2'); if($xml){ echo ' <table> <thead> <tr class="headings"> <th>Subject</th> <th>Tag</th> <th>Public Date</th> </tr> </thead> <tbody>'; foreach($xml->channel->item as $item){ echo '<tr> <td title="'.addslashes($item->description).'"> <a href="'.$item->link.'" target="_blank">'.$item->title.'</a> </td><td>'; $i=0; foreach($item->category as $val){ echo $i==0 ? $val : ', '.$val; $i++; } echo '</td><td>'.substr($item->pubDate,0,16).'</td> </tr>'; } echo ' </tbody></table> '; }else{ echo "Failed to open feed."; } ?> |
ดูข้อมูลเพิ่มเติม http://php.net/manual/en/function.simplexml-load-file.php
ป้ายกำกับ:rss, simplexml_load_file, xml