• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 67
  • Last Modified:

real_escape_string Usage

I use   $data = $mysqli->real_escape_string($data);
But the output has /r/n

Should i store it into my database like this?
What do you suggest i should do?
0
Braveheartli
Asked:
Braveheartli
  • 2
2 Solutions
 
Ray PaseurCommented:
You should store exactly what you need in the database.  If the \r\n (end-of-line characters) are meaningful, store them.  If not, you might want to use PHP trim() to remove them.
0
 
Julian HansenCommented:
The question is - do you need the \r\n in the string. For instance if it is at the end of the string you could probably trim() it. If it is in the string - as part of the formatting then you probably don't want to remove it.

The answer to the question is dependent on how the data will be viewed.

Any modifications to the data you make should be reversible to the extent that when displayed does not alter the intended layout of the data.

There is no problem with keeping the CR LF in the string.
0
 
Ray PaseurCommented:
See also: https://www.experts-exchange.com/questions/28983112/real-escape-string-Usage.html#a41887646
The output probably has backslashes like this: \r\n.  These are end-of-line ("EOL") characters, roughly termed "carriage return" and "new line."  They probably come from a PC file or document, since Unix uses only one EOL, the \n.


You should store them if they are meaningful in the context of the data and if your application needs them.  Otherwise you can trim() them off.  It is possible to remove them from the interior of a data string, but it's a little more involved, and it's less likely that you would want to make a change in the middle of a data string.

These EOL characters interact with real_escape_string() functions because they contain backslashes that have programmatic meaning (just like escaped apostrophes).  The MySQLi engine strips backslashes automatically, with the understanding that it expects to receive escaped data, and store exact representations of the data.
0
 
BraveheartliMarketingAuthor Commented:
Thank you
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now