简体   繁体   中英

Php Xpath query returning “Array”

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"

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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM