将变量添加到简单xml调用的末尾

时间:2012-10-30 13:19:22

标签: php xmlhttprequest

以下是我的代码,调用外部xml文件并以xml格式返回一些信息,如果我手动将值添加到url字符串的末尾,现在这可以正常工作,但是只要我将值替换为变量$ reg它不会返回任何结果。

$reg = $_POST['reg'];
$file = 'http://testsite.mywebsite.co.uk/app.xml?apikey=*******************&vid=TEST&vrm=$reg';
if(!$xml = simplexml_load_file($file))
 exit('Failed to open '.$file);
print_r($xml);

任何建议都会受到赞赏,因为我无法理解为什么它不起作用,我甚至尝试用引号括起来,但仍然没有。

由于

2 个答案:

答案 0 :(得分:1)

如果希望PHP解析字符串中的变量,请使用双引号:

$file = "http://testsite.mywebsite.co.uk/app.xml?apikey=*******************&vid=TEST&vrm=$reg";

答案 1 :(得分:0)

$reg = $_POST['reg'];
$file = 'http://testsite.mywebsite.co.uk/app.xml?pikey=*******************&vid=TEST&vrm='.$reg;
echo "Filename: " . $file; // < --- added this so that you can check the filename is correct
if(!$xml = simplexml_load_file($file)){
 exit('Failed to open '.$file);
}
print_r($xml);
相关问题