Displaying just one node using simplexml and GET
Posted: Sun May 22, 2005 5:42 pm
I'm trying to use PHP to display the contents of an XML document. I had no trouble creating a page that listed all of the items in my XML file. But what I want to do is create pages that display information from just one of the nodes in the XML file, using a URL like this: test.php?itemID=0
That displays this:
If I change '$itemID' to '0' in the last line, then the script does what it should:
What am I doing wrong? I don't get any errors. How do I select a specific node using a variable? I've been combing through the PHP manual, and googling 'simplexml' but I can't find the answer.
Code: Select all
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', TRUE);
$xmlstr = <<<XML
<?xml version='1.0' standalone='yes'?>
<tests>
<test>
<testtitle id="e;1"e;>I want to show this one.</testtitle>
<testtitle id="e;2"e;>Not this one.</testtitle>
</test>
</tests>
XML;
$xml = simplexml_load_string($xmlstr);
$itemID =$_GETї"e;itemID"e;];
$test=$xml->testї0];
?>
<p>Show <?php echo $itemID;?></p>
<p>Title: <?php echo $test->testtitleї$itemID]; ?></p>Code: Select all
Show 0
Title:Code: Select all
Show 0
Title: I want to show this one.