此代碼示出輸出爲:誤差在解析參數使用PHP
串(59) 「{」 狀態 「:{」 消息 「:」 錯誤解析 參數」, 「值」:14} }」
但當而不是 「file_get_contents
」 只 「echo
」 時,它顯示正確的URL作爲輸出:http://ws.geonames.org/countryCodeJSON?lat=20.992&lng=73.314&username=****
什麼錯誤嗎?
<?php
$servername = "localhost";
$username = "*******";
$password = "*************";
$dbname = "id1116502_kk";
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//remove limit 1 is you want multiple data.
$sql = "SELECT degree_n, minute_n,degree_e, minute_e FROM coordinates ORDER BY id DESC limit 1 ";
$result = $conn->query($sql);
$deg_e = "";
$min_e = "";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$deg_n = $row["degree_n"];
$min_n = $row["minute_n"];
$deg_e = $row["degree_e"];
$min_e = $row["minute_e"];
$url = file_get_contents('http://ws.geonames.org/countryCodeJSON?lat=$deg_n.$min_n&lng=$deg_e.$min_e&username=****');
var_dump($url);
}
} else {
echo "0 results";
}
$conn->close();
?>
您使用的是旅遊單引號'file_get_contents' – julekgwa
日Thnx ... ...解決好 –
,這是不可能的那樣的'echo'http://ws.geonames.org/countryCodeJSON?lat = $ deg_n。$ min_n&lng = $ deg_e。$ min_e&username = ****';'解析變量。 –