Save textarea line breaks

0

I'm using php and mysql, I need to replace the line breaks that I put in my textarea by \ n to save it in my database, I wanted to know how I can do this. Thanks!

    
asked by Patricio 27.10.2017 в 17:02
source

1 answer

3

I recommend you use the nl2br function.

This function replaces \ n with <br> .

Here I leave you a url: link

The inverse function does not exist, but you can create a function with regex , as follows:

<?php

    function br2nl($string)
    {
        return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $string);
    }

?>
    
answered by 27.10.2017 в 18:50