Php Xpath 查询返回“数组"
问题描述:
我得到了我的 xml 文件,还有我的 php 脚本
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"
答
访问 xpath
返回的 array
的元素...
Access the elements of the array
returned from xpath
...
PHP >= 5.4:
$title = $db->xpath($tq)[0];
PHP <5.4:
更新 PHP :-)
或
list($title,) = $db->xpath($tq);
或
$title = $db->xpath($tq);
$title = $title[0];