Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php解析参数时出错_Php_Mysql - Fatal编程技术网

使用php解析参数时出错

使用php解析参数时出错,php,mysql,Php,Mysql,此代码将输出显示为: 字符串(59)“{”状态“{”消息“:“错误分析” 参数“,”值“:14}” 但是当使用“file\u get\u contents”而不是“echo”时,它会将正确的url显示为输出:http://ws.geonames.org/countryCodeJSON?lat=20.992&lng=73.314&username=**** 这里出了什么问题 <?php $servername = "localhost"; $username = "****

此代码将输出显示为:

字符串(59)“{”状态“{”消息“:“错误分析” 参数“,”值“:14}”

但是当使用“
file\u get\u 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();

    ?>


您在
文件\u get\u内容中使用单引号

 // 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');

您在tour
文件中使用单引号获取内容
thnx…已解决…嗯,像
echo这样的东西是不可能的http://ws.geonames.org/countryCodeJSON?lat=$deg_n.$min_n&lng=$deg_e.$min_e&username=**解析变量。