PHP_EOL or \r\n

5 posts by 2 authors in: Forums > CMS Builder
Last Post: February 13, 2018   (RSS)

By ht1080z - February 2, 2018 - edited: February 2, 2018


I'm trying to remove the \r\n from the string that I inserted to textbox field (from textarea element) into MySQL.

No I cannot remove it displaying again from MySQL to HTML. There is so many solution out there but nothing works.

I tried with:

$orderNotes = str_replace("\r\n",' ', $orderRecord['notes']);
$orderNotes = trim(preg_replace( '/\s+/', ' ', trim($orderRecord['notes'])));
$orderNotes = str_replace(array("\r\n", "\r", "\n"), "", $orderRecord['notes']);
$orderNotes = trim(preg_replace('/\s\s+/', ' ', $orderRecord['notes']));

but my string is continue to echo out with \r\n. Nothing works....!

How can I remove this (or change to <br/>) or better how can I insert to MySQL without it?

Please advise,

PS: I found a solution, the only thing that works:

$orderNotes = str_ireplace(array("\r\n",'\r\n'),'<br />', $orderRecord['notes']);

By Djulia - February 2, 2018


Did you test with nl2br?

$orderNotes = nl2br($orderRecord['notes']);



By ht1080z - February 3, 2018

Hi Djulia,

Thanks for your suggestion! Yes, I tried it but with no luck, only the below code worked in my case:

$orderNotes = str_ireplace(array("\r\n",'\r\n'),'<br />', $orderRecord['notes']);

Any hint how can I remove the newline \r\n that in the $POST from textarea (or change to <br/>) before inserting to MySQL?

Dear iTools team,

I didn't getting notification emails from the forum anymore. How can I opt-in again?


By ht1080z - February 13, 2018

Thank you Djulia for your tips and support on this, sorry for not getting back to you sooner (still not getting forum email notifications).

My problem is when I try to output from MySQL cmsb textbox field where previously I stored from textarea with \r\n

Example (in Greek): Θέλω για ύφασμα το / 644c, (πουά μπλε)\r\nΌπως λέω σε όλες τις εκτυπωσεις

In my case the str_ireplace worked like I posted before.

Thank you again,