我正在尝试从用户那里获取输入 当我给出像“kaushik”这样的输入时,json输出不会出现
这是我的代码
<?php
if(!empty($_POST['name'])){
$name = strip_tags(@$_POST['name']);
//echo $name;
$json = '{
"a":"'.$name.'",
"b":"Kishore",
"c":"ramesh",
"d":"Suresh",
"e":"ramu"
}';
$jsonOutput = json_decode($json,true);
print_r($jsonOutput);
}
?>
<form name = "myform" action = "" method = "POST">
Name <input type = "name" name = "name"/></br>
<input type= "Submit" name = "submit" value = "show"/>
</form>
答案 0 :(得分:0)
您需要先取消双引号。即\"
代替"
$name = addslashes($name);
但是,通常您不希望自己生成JSON。你最好创建一个数组并让json_encode()
完成工作。