I am trying to pass a variable to an xpath expression
the value comes from a url ex: mysite.com/page.php?ids=2
When I hardcode the value in the Xpath
Code: Select all
$siteID = $xml->xpath('//blackboard/site[id="2"]/image');If try to get the value from the variable
Code: Select all
$siteID = $xml->xpath('//blackboard/site[id="$val"]/image');
Here is my code:
Code: Select all
$val = $_GET['ids'];
echo "the value is: $val";
$xml = simplexml_load_file('blackboard.xml');
$siteID = $xml->xpath('//blackboard/site[id="$val"]/image');
foreach($siteID as $image) { }
?>
<img src="http://localhost/frogvisionjuly08/images/<?php echo "$image"; ?>" />
Code: Select all
<blackboard>
<site>
<id>1</id>
<image>sites/stevenson.png</image>
<text>Stevenson's website</text>
</site>
<site>
<id>2</id>
<image>sites/sophie/sophie.jpg</image>
<text>Sophie's webiste</text>
</site>
</blackboard>
Thanks for looking
Chris
I have an xml document formated that way
Code: Select all
<blackboard>
<site>
<id>2</id>
<image>sites/sophie/sophie.jpg</image>
<text>Sophie Mckay Knight's website </text>
</site>
<site>
<id>1</id>
<image>sites/stevensonMarshall/blackboard.png</image>
<text>Stevenson and Marshall</text>
</site>
</blackboard>