duannuci4008 2017-04-21 09:22
浏览 93
已采纳

使用php [duplicate]解析参数时出错

This question already has an answer here:

This code showing the output as :

string(59) "{"status":{"message":"error parsing parameter","value":14}}"

but when instead of "file_get_contents" only "echo" is used, it shows correct url as output : http://ws.geonames.org/countryCodeJSON?lat=20.992&lng=73.314&username=****

what is going wrong here ?

 <?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();

    ?>
</div>
  • 写回答

1条回答 默认 最新

  • dongzhong5967 2017-04-21 09:29
    关注

    you are using single quotes in your 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法