我在将输入保存到数据库时遇到问题。
我将字符串保存到数据库中,格式为:
mysql_real_escape_string($my_string)然后,我读取该字符串,并使用以下命令将其放入输入:
stripslashes($my_string)关键是,如果我在字符串中设置了双斜杠,输入就会崩溃,如下所示:
<input maxlength = "150" type="text" name = "my_string12" value = "hello "this is" a test" class="input-medium"/>谢谢。
发布于 2013-05-04 19:33:35
如果值为PHP变量,则必须对其进行修剪。
使用trim函数:
$str = 'hello "this is" a test';
echo trim($str, '"'); // hello this is a test保罗在here回答
发布于 2013-05-04 20:14:46
您可以使用
<?php echo addslashes('hello "this is" a test'); // hello \"this is\" a test ?>
使用带斜杠将其删除
<?php echo stripslashes('hello \"this is\" a test'); // hello "this is" a test ?>
或者像这样输入
value = 'hello "this is" a test'或value = "hello 'this is' a test"
https://stackoverflow.com/questions/16373648
复制相似问题