Hi, how can i make a line break in a multi line html form to a <br /> for the database? Thanks 🙂
http://us2.php.net/nl2br
i have tried this but i cannot get it to work, how do the forums like this one automatically add the line breaks as they are typed? for example ...
line 1
line 2
ect line 3???
benracer, what exactly did you try?
How about
function nl2p($str) { $new_str = preg_replace('/<br \\/>\s*<br \\/>/', "</p>\\n<p>", nl2br($str)); return '<p>' . $new_str . '</p>' . "\n"; }
What i need is that when i post the contents of a textarea it to add the line breaks. At the moment when i just set it in a variable it creates one long string with no line breaks. As i said with this forum if i hit the enter key it produces the break in the post.
Well, as mentioned earlier nl2br() is the function to use. If you use it with say, htmlspecialchars(), as you probably should, remember to use it after calling the other function.
I'd further suggest using these functions on text after taking it out of the database, instead of before putting it in: the database content is then kept clean and potentially usable for other purposes.
Thanks Sorted 🙂