我正在尝试使用PHP变量从XML文件加载某些元素,因此如果加载了index.php?id = 1,它将从$ projects-> project [1]中提取信息。以下代码中没有出现错误,但没有显示任何内容。任何帮助表示赞赏:)
<?php
$projects = simplexml_load_file('portfolio.xml');
$id = $_GET["id"];
echo $projects->project[$id]->title;
?>
答案 0 :(得分:0)
它可能是两件事之一(或两件事):
也就是说,尝试使用print_r或var_dump来获取数据。
答案 1 :(得分:0)
的print_r($ _ GET);死; 检查你是否在获取数据中获取数据。
答案 2 :(得分:0)
error_reporting(~0); // show me everything i do wrong
$projects = simplexml_load_file('portfolio.xml');
var_dump($projects); // make sure $projects actually has something
var_dump($_GET['id']); // are you getting the request data?
$id = (int) $_GET["id"]; // cast to int for good measure
// i'm assuming it's numeric, don't if its not
echo $projects->project[$id]->title; // still not showing anything?
var_dump($projects->project[$id]->title); // dump it for good measure