PHP TUTORIALS - PHP and XML
PHP and XML
ADVERTISEMENTS
HTML list that is valid XML:
<ul>
<li>Braised Sea Cucumber</li>
<li>Baked Giblets with Salt</li>
<li>Abalone with Marrow and Duck Feet</li>
</ul>
|
ADVERTISEMENTS
Example:
<?php
$channel =<<<_XML_
<channel>
<title>What's For Dinner<title>
<link>http://menu.example.com/<link>
<description>Choose what to eat tonight.</description>
</channel>
_XML_;
$xml = simplexml_load_string($channel);
print "The $xml->title channel is available at $xml->link. ";
print "The description is \"$xml->description\"";
?>
|
ADVERTISEMENTS
The What's For Dinner channel is available at http://menu.example.com/. The description is "Choose what to eat tonight."
|
Example:
<?php
$channel = array('title' => "What's For Dinner",
'link' => 'http://menu.example.com/',
'description' => 'Choose what to eat tonight.');
print "<channel>\n";
foreach ($channel as $element => $content) {
print " <$element>";
print htmlentities($content);
print "</$element>\n";
}
print "</channel>";
?>
|
<channel>
<title>What's For Dinner</title>
<link>http://menu.example.com/</link>
<description>Choose what to eat tonight.</description>
</channel></html>
|