我有我的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>';
?>
它应该为他们显示“测试”!但它说“阵列”
答案 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];