我正在保存需要保存在数据库中的双引号,然后显示在屏幕上。
$in = '2" to 2.33"';
$in = mysqli_real_escape_string($db, $in);
echo $in; // Shows with backslashes
$results = $db->query("UPDATE store_item_brims SET BrimSizeIn='$in' WHERE ID=2");
// Later I query the database and load to an array
// print_r of the array shows with no backslashes
// echoing into text input field does not work
当我在PHPMyAdmin中查看数据时,它会在没有任何可见反斜杠的情况下保存在数据库中。当我将数据加载到数组并print_r
数组时,它将显示在数组中。但是,当我尝试在输入文本字段中回显它以供用户更新时,它只显示2
并在达到第一个双引号后立即切断。
我该如何解决这个问题?
答案 0 :(得分:1)
当你将它回显到HTML输入时,引号搞乱了HTML输入用作分隔符的引号这么短的答案:
<input type="text" value="<?php echo htmlentities($YOUR_VALUE); ?>" ...
参考:htmlentities