0

ive got my xml file and also heres my php script

 $db  =  simplexml_load_file("BIN/videos.xml");

$id = $_GET['id'];

$tq = "//video['@id=" . $id . "']/title[0]";
$dq = "//video['@id=" . $id . "']/description[1]";
$eq = "//video['@id=" . $id . "']/embed[2]";

$title  = $db->xpath($tq);

$description = $db->xpath($dq);

$embed  = $db->xpath($eq); 

include("design/lyt.php");

echo $embed . '<br>
<h1>' . $title . '</h1>
<p>' . $description . '</p>';

?>

Its supposed to display "Test" for them all! but it says "Array"

2
  • Can you post the XML, or at least a sample? Commented Nov 19, 2013 at 1:39
  • This question appears to be off-topic because the OP needs to RTFM. SimpleXMLElement::xpath returns an array Commented Nov 19, 2013 at 2:26

1 Answer 1

2

Access the elements of the array returned from xpath...

PHP >= 5.4:

$title  = $db->xpath($tq)[0];

PHP < 5.4:

Update PHP :-)

or

list($title,)  = $db->xpath($tq);

or

$title  = $db->xpath($tq);
$title = $title[0];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.