【问题标题】:Input crash on read slashes读取斜杠时输入崩溃
【发布时间】:2013-04-28 17:26:53
【问题描述】:

我在将输入保存到我的数据库时遇到问题。

我将字符串保存到我的数据库中:

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"/>

谢谢。

【问题讨论】:

  • 应该可以。但我不能告诉我的用户使用单引号而不是双斜杠...

标签: php mysql input crash


【解决方案1】:

如果值是 PHP 变量,那么你必须修剪它..

使用修剪功能:

$str = 'hello "this is" a test';
echo trim($str, '"'); // hello this is a test

保罗在here回答了

【讨论】:

    【解决方案2】:

    你可以使用

    &lt;?php echo addslashes('hello "this is" a test'); // hello \"this is\" a test ?&gt;

    用斜线删除它

    &lt;?php echo stripslashes('hello \"this is\" a test'); // hello "this is" a test ?&gt;

    或者直接这样输入

    value = 'hello "this is" a test'value = "hello 'this is' a test"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-24
      • 2017-11-03
      • 2012-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多