2012-10-30 67 views
0

ok下面是我的代碼,調用一個外部xml文件並返回一些XML格式的信息,現在這工作完美,如果我手動將值添加到URL字符串的末尾,但是隻要我用變量$ reg替換它的值就不會返回任何結果。添加變量到一個簡單的xml調用結束

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

任何建議,將不勝感激,因爲我不明白爲什麼它不會工作,我甚至試過在引號包裹,但仍然一無所獲。

感謝,如果你想PHP到你的字符串中解析變量

+0

使用的字符串雙引號,而不是單引號。或者將'$ reg'連接到它。變量'$ reg'只能插入雙引號字符串中。 –

+0

echo $ file就在你設定之後,這樣你就可以看到你所要求的網址是... – Chris

回答

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); 
1

使用雙引號:

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