pass variable to xpath?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am trying to find out if there is a way to pass a variable $fquote to
xpath ...[qtnum="help"]
$fquote would be derived from a form. Any help may save what is left of my

$s = simplexml_load_file('fishquotes.xml');
$fquote = "245";
$findquote = $s->xpath('/fishingquotes/quote[qtnum="260"]');

<?xml version="1.0"?>
<fishingquotes xmlns:xsi=" ">
  <title>Small Fish</title>
  <copy>Govern a family as you would</copy>
  <copy> cook a small fish; </copy>
  <copy>very gently.</copy>
  <author> Chinese Proverb</author>
 <!--and 450 more quotes-->

Tony Bishop
New Zealand

Tony Bishop
New Zealand

Re: pass variable to xpath?

Quoted text here. Click to load it

Looks like you are asking a very basic string question. Time to RTFM?
Hard to tell since you didn't ask a specific question. What is supposted
to happen with $fquote? Should it be used instead of the hardcoded 260


See the difference between single quoted strings and double quoted:

echo "foo='$foo'\n";
echo 'foo="$foo"\n';
echo "foo=\"$foo\"\n";
echo 'foo="'.$foo.'"\n';
echo "etc.\n";

So maybe you are looking for:

In that case $fquote has to be "XML escaped" (see htmlspecialchars()).

Re: pass variable to xpath?

Thanks Daniel - you answered the question I did not ask  - something about
wood and trees springs to mind :-)

Tony Bishop
New Zealand

Site Timeline