如何使用 POST 创建 json 数组


How do I create a json array using POST?

请忘记我糟糕的英语。

我使用 GD 库创建了一个简单的应用程序,但在表单上必须通知图像中的文本,填充 x 和 y 填充,这些文本将在 PHP 的 DG 变量中接收:$ title、$ x 和 $ y。

在文件形式中.php我有一个简单的表单:

  <form method = "POST">
   Title <input type = "text">
    X <input type = "text">
    Y <input type = "text">
   / * Others fields * /
</ form>

我不知道如何使用表单中的数据创建一个 json,然后我继续使用 php:

$ json = json_decode ($ jsondata, true);
这是截

取的小代码,允许您执行此操作:

<form method = "POST">
    Title <input name="title" type = "text">
    X <input name="x" type = "text">
    Y <input name="y" type = "text">
    <!-- other fields -->
    <input type="submit" value="Submit">
</form>

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $json = json_encode($_POST);
    echo $json;
}
?>