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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵