2012-07-09 36 views
0

我已經在php中編寫了一個文件,這個文件正在做一些幕後工作,並根據位置GET參數返回一個簡單的數字,在這種情況下輸出是49,請自己查看,剪切並粘貼到瀏覽器:奇數php file_get_contents行爲

http://www.ericseven.com/distance.php?location=3133 W. Belle Ave San Tan Valley, AZ 85142

當我拉這個到另一個PHP文件,我想用數字做一些計算着,它返回,莫名其妙地,不同數量(在這種情況下7174,如你可以看看你是否點擊下面的URL):

http://www.ericseven.com/test.php

這是test.php的來源 - 請注意,$ url是與上面相同的位置參數(這是一個剪切和粘貼):

$url = "http://www.ericseven.com/distance.php?location=3133 W. Belle Ave San Tan Valley, AZ 85142"; 
$contents = file_get_contents($url); 
echo $contents; 

我已經搜查,搜查和我不不知道我是否在搜尋錯誤或交易是什麼,但是我找不到兩個數字(49和7174)之間的任何關係,我也找不到任何處理類似事情的人。僅供參考我試過fopen/fread - 結果相同。

+0

urlencode確實是解決方案。謝謝! – user1512672 2012-07-10 00:18:29

回答

2

嘗試

$url = "http://www.ericseven.com/distance.php?location=".urlencode("3133 W. Belle Ave San Tan Valley, AZ 85142"); 
2

你需要編碼的URL。

<?php 
$location = "3133 W. Belle Ave San Tan Valley, AZ 85142"; 
$url = 'http://www.ericseven.com/distance.php?location='.urlencode($location); 
$contents = file_get_contents($url); 
echo $contents; 
?>