Php Xpath 查询返回“数组" [英] Php Xpath query returning "Array"

查看:35
本文介绍了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];

这篇关于Php Xpath 查询返回“数组"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆