[kdewebdev-site] FAQ (in text)
Chris Martin
linux at chriscodes.com
Wed Feb 23 04:13:14 EST 2005
Andras Mantia wrote:
> - who will write the PHP parser engine which creates HTML from XML?
Here's how ... err, simple.. XML is in php5 with the simpleXML function.
I added a second "faq" to the sample xml for looping purposes.
I also have a function that will parse XML, that works in PHP 4, and
there are a few classes that do this.
<?php
$faqXml = <<<FAQXML
<faqs>
<faq>
<question>the question 1</question>
<answer>the answer 1</answer>
<maintainer name="name" email="email" />
<category name="category" />
<product name="product" />
</faq>
<faq>
<question>the question 2</question>
<answer>the answer 2</answer>
<maintainer name="name" email="email" />
<category name="category" />
<product name="product" />
</faq>
</faqs>
FAQXML;
$xml = simplexml_load_string($faqXml);
// access by individual element
echo $xml->faq[0]->question;
// or loop
foreach( $xml->faq as $item ) {
echo $item->question."\n";
}
?>
--
Chris Martin
Web Developer
Open Source & Web Standards Advocate
http://www.chriscodes.com/
More information about the kdewebdev-site
mailing list