Page 328 - Open Soource Technologies 304.indd
P. 328
Web Technologies-I
Notes your php.ini file, or simply echo the line from within PHP code:
<? php echo ‘<?xml version=”1.0” encoding=”ISO-8859-1” ?>’; ?>
Example generates an RSS document using PHP. An RSS file is an XML document containing
several channel elements, each of which contains some news item elements. More properties of
an item are supported by RSS than the Example creates. Just as there are no special functions
for generating HTML from PHP (you just echo it), there are no special functions for generating
XML. You just echo it!
Generating an XML document.
<?php header(‘Content-Type: text/xml’); ?>
<?xml version=’1.0’ encoding=’ISO-8859-1’ ?>
<!DOCTYPE rss PUBLIC ‘-//Netscape Communications//DTD RSS 0.91//EN’
‘http://my.netscape.com/publish/formats/rss-0.91.dtd’>
<rss version=”0.91”>
<channel>
<?php
// news items to produce RSS for
$items = array(
array(‘title’ => ‘Man Bites Dog’,
‘link’ => ‘http://www.example.com/dog.php’,
‘desc’ => ‘Ironic turnaround!’),
array(‘title’ => ‘Medical Breakthrough!’,
‘link’ => ‘http://www.example.com/doc.php’,
‘desc’ => ‘Doctors announced a cure for me.’)
);
foreach($items as $item) {
echo “<item>\n”;
echo “ <title>{$item[title]}</title>\n”;
echo “ <link>{$item[link]}</link>\n”;
echo “ <description>{$item[desc]}</description>\n”;
echo “ <language>en-us</language>\n”;
echo “</item>\n”;
}
?>
</channel>
</rss>
322 LOVELY PROFESSIONAL UNIVERSITY