codescracker


php

PHP and XML



« Previous Tutorial CodesCracker Home »


XML is a markup language that looks a lot like HTML. An XML document is plain text and contains tags delimited by < and >

HTML list that is not valid XML

<ul>
<li>list item one
<li>list item two
<li>list item three
</ul>

HTML list that is valid XML

<ul>
<li>list item one</li>
<li>list item two</li>
<li>list item three</li>
</ul>

Parsing an XML Document using PHP5

<?php

$channel =<<<_XML_
<channel>
<title>What's For Today's Dinner<title>
<link>http://menu.example.com/<link>
<description>Choose what to eat :</description>
</channel>
_XML_;

$xml = simplexml_load_string($channel);
print "The $xml->title channel is available at $xml->link. ";
print "The description is \"$xml->description\"";
?>

It will produce the following result:

The What's For Today's Dinner channel is available at http://menu.example.com/. The description is "Choose what to eat :"

« Previous Tutorial CodesCracker Home »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test