Php Xpath查询返回“数组”

时间:2013-11-19 01:36:38

标签: php xpath simplexml

我有我的xml文件,还有我的php脚本     

 $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>';

?>

它应该为他们显示“测试”!但它说“阵列”

1 个答案:

答案 0 :(得分:2)

访问从array ...

返回的xpath元素

PHP&gt; = 5.4:

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

PHP&lt; 5.4:

更新PHP: - )

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

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