Solved

real_escape_string Usage

Posted on 2016-11-15
4
20 Views
Last Modified: 2016-11-15
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
Comment
Question by:Braveheartli
  • 2
4 Comments
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 41887632
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
 
LVL 52

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 41887638
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
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41887649
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
 
LVL 1

Author Closing Comment

by:Braveheartli
ID: 41887978
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now