首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取斜杠时输入崩溃

问读取斜杠时输入崩溃
EN

Stack Overflow用户
提问于 2013-05-04 19:13:55
回答 2查看 130关注 0票数 0

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

我将字符串保存到数据库中,格式为:

代码语言:javascript
复制
mysql_real_escape_string($my_string)

然后,我读取该字符串,并使用以下命令将其放入输入:

代码语言:javascript
复制
stripslashes($my_string)

关键是,如果我在字符串中设置了双斜杠,输入就会崩溃,如下所示:

代码语言:javascript
复制
<input maxlength = "150" type="text" name = "my_string12" value = "hello "this is" a test"  class="input-medium"/>

谢谢。

EN

回答 2

Stack Overflow用户

发布于 2013-05-04 19:33:35

如果值为PHP变量,则必须对其进行修剪。

使用trim函数:

代码语言:javascript
复制
$str = 'hello "this is" a test';
echo trim($str, '"'); // hello this is a test

保罗在here回答

票数 0
EN

Stack Overflow用户

发布于 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"

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16373648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档