我是JSON和PHP新手,需要一些帮助!我有一些json,想user
用_GET搜索,并返回有关该用户的所有信息。
JSON:
{
Shawn Taylor: {
user: "Shawn Taylor",
email: "[email protected]",
phone: "604-123-4567"
},
John Smith: {
user: "John Smith",
email: "[email protected]",
phone: "604-123-4569"
}
形式:
<form method="get">
<input name="find" />
<button type="submit">Find</button>
</form>
PHP:
if (!empty($_GET['find'])){
$find = ($_GET['find']);
$data_url = 'data.json';
$data_json = file_get_contents($data_url);
$data_array = json_decode($data_json, true);
echo $data_array['user'];
echo $data_array['email'];
echo $data_array['phone'];
我认为这应该可行,但是没有运气。有人可以帮忙吗?
您只是忘了用$find
钥匙找到它。
尝试一下(看最后4行):
if (!empty($_GET['find'])){
$find = ($_GET['find']);
$data_url = 'data.json';
$data_json = file_get_contents($data_url);
$data_array = json_decode($data_json, true);
$user = $data_array[$find];
echo $user['user'];
echo $user['email'];
echo $user['phone'];
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句