How do I store line-breaks from textarea properly in mySQL database? How do I store line-breaks from textarea properly in mySQL database? codeigniter codeigniter

How do I store line-breaks from textarea properly in mySQL database?


Okay I've found the answer. I'm using CI 2.0, and it is an existing bug that has already been reported.https://bitbucket.org/ellislab/codeigniter/issue/332/newlines-in-textareas-are-duplicated

The quick fix is as below (look for the file in /system/core/Input.php)

//$str = str_replace(array( "\r\n", "\r"), PHP_EOL, $str);$str = preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str);

Hope this helps someone out there.


It seems like a newline is being added after each new line. This has to do with how the data is inserted into the database. Care to share that code?


try to use \n in database and when you showing record use nl2br()

for more