PHP Sanitized markdown - html 输出
我的网站上有 WMD 编辑器,并将降价存储在数据库中。但在我将降价发送到数据库之前,我使用 mysql_real_escape_string 对其进行过滤,如下所示:
$to_database = mysql_real_escape_string($_POST['markdown']);
没关系。但现在我想展示它,所以我使用 PHP Markdown (它将 markdown 转换为 html)。但问题是它显示了 \r\n 和 \n 而不是新行。我尝试了 nl2br 功能,但没有帮助。即使我不转义输出(不将 markdown 转换为 html 并使用 htmlpurifier),我仍然得到 \n 而不是新行。 仅当我删除 mysql_real_escape_string 时,它看起来才正常。
bbbbbbbbbb 嗯嗯嗯
I have WMD editor on my site, and i store the markdown in the DB. But before i send the markdown to database i filter it with mysql_real_escape_string, like that:
$to_database = mysql_real_escape_string($_POST['markdown']);
And it's okay. But now I want to show it, so i use PHP Markdown (which converts markdown to html). But the problem is that it shows me \r\n and \n instead of new lines. I tried nl2br function, but it didn't help. Even if I do not escape the output (do not convert markdown to html and using htmlpurifier) I still get \n instead of new lines.
Only when I remove mysql_real_escape_string it looks fine.
bbbbbbbbbbb
nnnnnnnnn
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的输入层上可能有一些东西,并使用反斜杠转义传入的字符,因此当您使用 mysql_real_escape_string 时,您实际上会获得双重转义的内容。
如果你很不幸,那件事可能是
magic_quotes_gpc
在这种情况下你应该 尽快摆脱它,或者如果你真的不能,那么解决这个问题。You may have something sitting on your input layer and escaping incoming characters with backslashes, so that when you use
mysql_real_escape_string
you're actually getting double-escaped content.If you are very unlucky that thing might be
magic_quotes_gpc
in which case you should get rid of it ASAP, or if you really can't then work around it.它们正在被转换并且不再充当换行符。您想要替换它们:
您可能还想这样做:
They are being converted and are no longer acting as line breaks. You want to replace them:
You might also want to do this: