1

当我提供像“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>
4

1 回答 1

0

您需要先转义双引号。即\"代替"

$name = addslashes($name);

但是,通常您不想自己生成 JSON。您最好创建一个数组并让其json_encode()完成工作。

于 2013-10-15T14:04:55.577 回答