2017-04-21 81 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