2017-04-21 84 views
0

此代碼示出輸出爲:誤差在解析參數使用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(); 

    ?> 
+0

您使用的是旅遊單引號'file_get_contents' – julekgwa

+0

日Thnx ... ...解決好 –

+0

,這是不可能的那樣的'echo'http://ws.geonames.org/countryCodeJSON?lat = $ deg_n。$ min_n&lng = $ deg_e。$ min_e&username = ****';'解析變量。 –

回答

1

您在使用單引號您file_get_contents

// change this to double quotes 
$url = file_get_contents('http://ws.geonames.org/countryCodeJSON?lat=$deg_n.$min_n&lng=$deg_e.$min_e&username=krunal123'); 

for more info check this post

+1

[更多信息](http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – DarkBee