(I think I used to know this...)

On my form, I've got a textbox and I store the input in a database. To retain line breaks and apostrophes, I use nl2br at the time of insertion.

But, this is an editable area, so when the information is retrieved and put into the textbox for editing , how do I make it so that the user doesn't see <br> tags?

    if you are storing the input into a database and then back to the textbox, you shouldnt have to use nl2br, that is really only needed when you want to display the newlines in a textbox as breaks. if you dont use it, when you put the contents back into the textbox the \n's will be shown as newlines in the textbox.

      It's not just going back into the textbox. It's viewable as well. So, I do need nl2br to store it, and something else to remove the tags when it's put into a textbox.

        i think its easier to store it as normal in the in the db, when you need to display it use nl2br. otherwise you can just use
        $str = str_replace('<br />', "\n", $str);
        to un nl2br it.

          drew010 is right.

          You should always try to store information "as is" in a DB, and then, change it when it comes to display it. Of course, you should analyse and verify the information before storing it to prevent "bad things" 😉

          Since I'm a French speaker, I need to convert accents (à, è, é, ê, ...) in ascii codes (&agrave;, &egrave;, &eacute;, ...), BUT I only do it when I need to display the information. In MySQL, accents are as is, i.e. "à, è, é, ê, ...", then in PHP, I use htmlentities() to "change" them 😉

            Write a Reply...