Here is what I want to do where users post forum post on my site....
It will add a new line automatically if you press enter. If you use html code then it will not add a new line automatically.
How can I achieve this? I know how to add new line breaks but not how to do it when a user has html code
Use [man]nl2br/man.
so if a user posted for example on my site a flash movie where the code had many lines, then wouldn't it try to insert a <BR> even where the html code breaks the line
right now I have been using
function lineBR($string){ $string = preg_replace("/\r\n|\n|\r/", "<br>", $string); return $string; }
but this adds a <br> tag to every new line even if the line break is from other html code posted
Oh, I understand it better now.
Check the text for HTML code. If there are none, use nl2br().