0
我有一个注释框表单并且正在运行,而我刚注意到当我使用'
时,它在它前面创建了一个\
。例如,如果我写了“如何”,它会显示为数据库中发布的内容以及显示在页面上的“如何”。当我显示“body”文本时,我使用stripslashes
函数,我认为这是应该去掉斜线。尽管使用反斜线,斜线显示在显示的文本中
我的服务器运行PHP版本5.3.6,如果有帮助。
我使用这段代码从注释框的正文文本张贴到我的数据库:
$body = mysql_prep($_POST['body']);
它使用的功能是这样的:
function mysql_prep($string) {
global $connection;
$escaped_string = mysqli_real_escape_string($connection, $string);
return $escaped_string;
}
方请注意:你不需要回答这个问题,但这是我用来让文本用户免受黑客,坏人和其他所有人伤害的功能。我做得那么好,还是让我自己面对问题? (除了这个斜杠的问题,可能是因为此功能)
这是我用来显示文本代码:
<div id="comments">
<?php while($comment_text = mysqli_fetch_assoc($display_comments)) { ?>
<div class="comment" style="margin-bottom: 2em;">
<div class="author">
<b><?php echo htmlentities($comment_text["author"]); ?>:</b>
</div>
<div class="meta-info" style="font-size: 0.8em;">
<?php echo datetime_to_text($comment_text["created"]); ?>
</div>
<div class="body">
<?php echo stripslashes($comment_text["body"], '<strong><em><p>'); ?>
</div>
</div>
<?php } ?>
<?php if(empty($display_comments)) { echo "No Comments."; } ?>
</div>
任何帮助或建议是超级感谢,谢谢!
我没有看到'stripslashes()'。我只看到'strip_tags()'(它做了其他的事情)。 –
在准备MySQLi查询时,您不需要'mysqli_real_escape_string()'函数。 –
哦当然,你的右@Gerald Schneider!我想我会把它拿出来,然后放入反斜杠?除非我正在搞这样做...... – coolpup