Ale*_*lex 4 php json escaping character
这是我的代码的简化版本,我遇到了问题.
$variable = "{\\\"JSON" //long JSON string created in Javascript with JSON.stringify
?> <input type="text" name="somename" value="<?php echo $variable; ?>"/> <?php
Run Code Online (Sandbox Code Playgroud)
输入框只包含{\我需要一种方法来转义整个JSON字符串
谢谢Alex
Mar*_*c B 14
您正在输出到HTML上下文中,因此您需要特定于html的转义:
<input ... value="<?php echo htmlspecialchars(json_encode($whatever)); ?>" />
^^^^^^^^^^^^^^^^----
Run Code Online (Sandbox Code Playgroud)