使用 php 从服务器 url 获取数据


Get data from server url using php

如何从我的服务器URL获取包含这些json数据的数据。我使用了这样的 api:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
  <title>_checksmsfrom</title>
</head>
<body>
<form action="https://cc.frifon.net/_checksmsfrom/" method="post">
  <table>
    <tbody>
      <tr>
        <td>SIP</td>
        <td><input name="sip" type="text"></td>
      </tr>
      <tr>
        <td>UUID</td>
        <td><input name="uuid" type="text"></td>
      </tr>
      <tr>
        <td>PWD</td>
        <td><input name="pwd" type="text"></td>
      </tr>
      <tr>
        <td>To</td>
        <td><input name="to" type="text"></td>
      </tr>
      <tr>
        <td>Since</td>
        <td><input name="since" type="text"></td>
      </tr>
      <tr>
        <td>Key<br>
        </td>
        <td><input readonly="readonly" name="key" value="190qopAKL"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input name="submit" value="Submit" type="submit"></td>
      </tr>
    </tbody>
  </table>
</form>
</body>
</html>

json数据显示如下:

{"status":0,"message":[["60146600472","##IMAGE##showpic.php?file=1380253368Cars 4 Ford Mustang Classic.jpg##IMAGE##","1380253368"],["60134194410","Gdgdgd","1380789783"],["60134194410","Gdgdtst","1380789810"],["60134194410","Ghdgdhdgdgdtdtdgdg","1380789834"],["60134194410","Tdtdsgdgdgdgdgs","1380789840"],["60134194410","Gdgdgxfhbhgjgu hvhfh 'n Hdhcbch'n Jfjvjv. Jgmbkb'n Jbjbjbjbj","1380789862"],["60134194410","Ggdgdg","1381139453"],["60134194410","Ffhfdet","1381389492"],["60146600472","assadasa sad","1382434816"],["60146600472","sdasdsad","1382441655"],["60146600472","cubaaaaaaaa","1382493484"]],"read":["1380253368"]}

那么我如何在我的网页中以数组显示或解析此 JSON 数据. 请我坚持几周。

从 PHP 5.2.0 开始,有一个名为 json_encode() 的函数可以获取任何有组织的数据并为您正确编码。

只需将您的表单发布到将执行以下操作的页面:

                        $res = array();
                        $res["code"] = 200;
                        $res["message"] = "OK";
                        $res["companies"] = array("Coca-Cola", "Apple")

然后打印该输出:

echo json_encode($res)

例如,这将为您提供:

{"code":200,"message":"OK","companies":[Coca-Cola, Apple]}

相应地修改。

虽然老实说,我不知道你为什么要发布到这样的页面。像这样的请求通常由服务器而不是用户给出。做你需要做的事情,我猜。

编辑:

如果需要,也可以解码请求。如果您的表单正在发送生成的 JSON 请求,请使用 json_decode()。并不是说我建议使用 POST 表单执行此操作,但同样,做您需要做的事情。