Building a web app that includes several contentEditable divs. The users add stuff to the div's, clicks the save button, which saves all the data from each div to a json object. That goes through JSON.stringify
to a mysql database as a TEXT (uploaded with php via mysql_real_escape_string()
). When loaded it goes back to JSON.parse
and then via javascript and jquery is placed back where it was.
The only issue is that newline characters are not replaced.
Is there a quick fix to this?
views:
50answers:
1
+3
A:
New line characters in HTML are ignored. What you need is <br/>
tags to replace the newlines, and PHP has the perfect function for you. nl2br() will replace the newlines with these tags and should return the output you're expecting.
$string = "some text\nwith\nnewlines";
echo nl2br($string);
// should return "some text<br/>with<br/>newlines"
thetaiko
2010-07-10 16:21:08