Php 如何将表单响应转换为html
以下是我的表单html代码:Php 如何将表单响应转换为html,php,json,Php,Json,以下是我的表单html代码: <form action="mysite.com/searchNum" method="post"> <div> <label for="say">Number</label> <input name="num" id="num" value=""> </div>` <div> <button>Sen
<form action="mysite.com/searchNum" method="post">
<div>
<label for="say">Number</label>
<input name="num" id="num" value="">
</div>`
<div>
<button>Send</button>
</div>
</form>
如何以以下格式显示响应数据并在其他页面上显示
(data.html):<br>
Name : ___<br>
Number: ______<br>
Cnic: ________<br>
Address : ________<br>
activation date: _______
(data.html):
名称:_;
编号:____;
Cnic:u_____;
地址:\\\\\\\\\\\\\\
启用日期:_______
使用$\u POST
变量。它只是一个数组,可以循环,也可以通过单个元素访问,比如$\u POST['message']
等等。但是你有一个json字符串?因此,您可以按照以下示例进行访问:
现在您有了一个json字符串,您可以简单地:
$json_string = '{
"message": "Successfully retrived",
"error": false,
"result": [{
"id": 6128071,
"name": "jhon doe",
"number": "31231231230",
"city": "C",
"cnic": "8982378237897278",
"address": "address123",
"activation_date": "0"
}]
}';
然后将json文件解码为数组:
$json_array = json_decode($json_string, true);
json字符串将成为关联数组:
Array
(
[message] => Successfully retrived
[error] =>
[result] => Array
(
[0] => Array
(
[id] => 6128071
[name] => jhon doe
[number] => 31231231230
[city] => C
[cnic] => 8982378237897278
[address] => address123
[activation_date] => 0
)
)
)
然后可以像这样访问:
{
"message": "Successfully retrived",
"error": false,
"result": [{
"id": 6128071,
"name": "jhon doe",
"number": "31231231230",
"city": "C",
"cnic": "8982378237897278",
"address": "address123",
"activation_date": "0"
}]
}
echo $json_array['message'];
现在,对于您想要实现的目标,只需执行以下操作:
Name : <?=$json_array['result']['name']?><br>
Number: <?=$json_array['result']['number']?><br>
Cnic: <?=$json_array['result']['cnic']?><br>
Address : <?=$json_array['result']['address']?><br>
activation date: <?=$json_array['result']['activation_date']?>
名称:
编号:
Cnic:
地址:
启用日期:
这个问题有点宽泛。您标记了php,那么您的php文件是什么样子的,到目前为止您尝试了什么?你到底被困在哪里了?谢谢。但是我如何在另一页上显示这个呢。当用户点击提交按钮时,它会像数据一样将他发送到页面。我不确定我是否完全理解。当您发布表单时,您在做什么?当用户单击“提交”时,将显示搜索结果。如何将此结果显示到其他页面当用户单击“提交”时,它会将其发送到,但我希望当用户单击“提交”时,它会将其发送到显示数据的data.html。将表单操作
更改为data.html
?