遇到转义引号问题,php
我有一个 for 循环,它运行一组问题,每个问题旁边都有一个文本区域。但是,如果问题或答案中包含撇号(就好像有人在问题中问“不要”或“不能”),它不会被插入到数据库中。我尝试过去掉斜杠并添加斜杠来解决问题,但没有成功。
这就是我到目前为止所得到的。
for 循环向用户显示不带斜杠的问题。
for($i = 0; $i< sizeof($answered); $i++)
{
echo "<h3><center>" . stripslashes($question[$i]) . "</center></h3>";
show_form($question[$i]);
}
和 POST 设置:
if ( !empty($_POST['answer']) )
{
$quest = mysqli_real_escape_string ($dbc, $_POST['question']);
$answer = mysqli_real_escape_string ($dbc, $_POST['answer']);
}
I have a for loop that runs through a set of questions with a text area next to each question. But if the question or answer has an apostrophe in it (as if someone asked "Don't" or "Can't" in the question), it doesn't get inserted into the database. I've tried strip slashes and add slashes to get rid of the problem to no avail.
This is what I've got so far.
The for loop to display to the user the question without slashes.
for($i = 0; $i< sizeof($answered); $i++)
{
echo "<h3><center>" . stripslashes($question[$i]) . "</center></h3>";
show_form($question[$i]);
}
and the POST setup:
if ( !empty($_POST['answer']) )
{
$quest = mysqli_real_escape_string ($dbc, $_POST['question']);
$answer = mysqli_real_escape_string ($dbc, $_POST['answer']);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 php.ini 文件中的magic_quotes_gpc是否已启用。
如果启用了 magic_quotes_gpc,请首先对数据应用 stripslashes()。
对已经转义的数据使用此函数将转义数据两次。
Check whether the magic_quotes_gpc is enabled in your php.ini file.
If magic_quotes_gpc is enabled, first apply stripslashes() to the data.
Using this function on data which has already been escaped will escape the data twice.
在 php.ini 中设置
magic_quotes_gpc = Off
或
在 .htaccess 中添加
php_flag magic_quotes_gpc Off
set
magic_quotes_gpc = Off
in your php.iniOR
add
php_flag magic_quotes_gpc Off
in your .htaccess尝试
htmlentities($question[$i], ENT_QUOTES);
存储数据,并使用html_entity_decode($question[$i], ENT_QUOTES);
显示数据。Try
htmlentities($question[$i], ENT_QUOTES);
to store the data, andhtml_entity_decode($question[$i], ENT_QUOTES);
to display it.