我想使用PHP代码使用URL从服务器中提取数据库

时间:2017-03-22 05:38:44

标签: php

http://www.amazinglaundryservices.com/hybrid_app/staging_webservices/get_location_area.php

这是我的链接。我想从这个链接获取数据,并使用php代码以表格格式显示它。

1 个答案:

答案 0 :(得分:0)

在php

中使用file_get_contents()

file_get_contents()将文件读入字符串。

此函数是将文件内容读入字符串的首选方法。因为它将使用内存映射技术,如果服务器支持这种技术,则可以提高性能。

  

语法 file_get_contents(path,include_path,context,start,max_length)

<?php
    $data = file_get_contents("http://www.amazinglaundryservices.com/hybrid_app/staging_webservices/get_location_area.php");
    //echo "<pre>";
    //print_R(json_decode($data, true));
    $fileData = json_decode($data, true);
    echo "<table border='1px solid'><tr><td>area_key</td><td>location_area</td><td>sort_key</td></tr>";
    foreach($fileData as $val) {
        echo "<tr><td>".$val['area_key']."</td><td>".$val['location_area']."</td><td>".$val['sort_key']."</td></tr>";
    }
    echo "</table>";
    ?>