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 关于#Mybatis#的问题:怎么办重复数据如下"KSDM":37,"KSMC":"呼吸内科门诊","ksdm":37,"ksmc":"呼吸内科门诊"xml文件填写
  • ¥40 servlet的web程序部署出错
  • ¥50 activiti 新建流程系列问题
  • ¥50 为什么我版本升级之后运行速度变慢5倍??
  • ¥15 如何在gazebo中加载机械臂和机械手
  • ¥15 纯运放实现隔离采样方案设计
  • ¥20 easyconnect无法连接后缀带.com的网站,一直显示找不到服务器ip地址,但是带有数字的网站又是可以连接上的,如何解决
  • ¥15 电脑开机过商标后就直接这样,求解各位
  • ¥15 mysql , 用自己创建的本地主机和用户名 登录不上
  • ¥15 关于#web项目#的问题,请各位专家解答!