双mysql_real_escape_string插入新行字符。如何获得新的换行符? [英] Double mysql_real_escape_string insert of new line characters. How to get new line breaks back?

查看:129
本文介绍了双mysql_real_escape_string插入新行字符。如何获得新的换行符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个textarea字段被插入到可能包含换行符的mysql数据库中。 textarea数据意外地经历了两批mysql_real_escape_string函数。因此,现场数据的换行符现在被存储为\r\\\
而不是实际的新行,因为它已被双重转义?



现在,当写回到textarea html字段进行编辑时,显示\r\\\
而不是新行。



问题:如何纠正所以这些实际上又变成新行了?

解决方案

您可能会使用mysql_real_escape字符串两次进行转义 - 作为输入过滤器(错误! )并作为SQL数据准备。你必须摆脱第一个。

或者一次,作为输入过滤器,然后使用预处理语句进行查询。摆脱第一个。


I have a textarea field that's inserted into a mysql database which may contain line breaks. The textarea data has accidentally gone through two lots of mysql_real_escape_string functions. Therefore the line-break bit of the field data is now stored as "\r\n" instead of an actual new line, as it's been double escaped?

Now when written back to the textarea html field for editing, "\r\n" is shown instead of a new line.

Question: How do I rectify the situation so these actually become new lines again?

解决方案

You are probably do escaping using mysql_real_escape string twice - as input filter (wrong!) and as a SQL data preparation. You have to get rid of the first one.

Or once, as input filter, and then use prepared statements for the query. Get rid of the first one as well.

这篇关于双mysql_real_escape_string插入新行字符。如何获得新的换行符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆