I’m using a comment box to submit comments. Users when entered any comment and press enter for a new line then after submit I used to update it to database using $update=mysql_real_escape_string($update); for security purpose.
But when that comment is shown the new line was replaced by alphabet ‘n’ and the whole sentence which should come like this
John is awesome
He loves food
comes like:
John is awesome nHe loves food
I searched the error in stack and found a solution:
I replaced <?php echo $message; ?> with <?php echo str_replace('\n',"<br/>", $message); ?> which did the job. but when I tried commenting 'n' it comes out to be \'n\' any solution for that?
Updated:
stripslashes should take care of the
\'n\'problem as well as many others.Note that the order of these commands matters. If you strip slashes first, you’ll mess up the str_replace. If you use htmlspecialchars after str_replace, it will mess up your
<br/>.