one preg_replace

A

Anonymous

Guest
I don't know what you exactly want to do, but perhaps you could use this:
Code:
str_replace('\r\n','<br>',$subject_value);
this will simply change a complete string.

as far as I know "\r\n" works normally in an textarea, so you won't have to replace those when creating a form.
You will only need to replace them when you're placing the code outside input fields in you're html-page. But than I allways manage with str_replace.

Hope this helps

Greetz Daan
 
To display a new line in a text area you need to use the html code for a new line character which is
. \r\n will only work in scripting languages, like PHP and Javascript because they can recognise spaces. HTML truncates spaces (except if you use the <pre></pre> tags which does not format data at all, perfect for viewing arrays with the print_r() function neatly)

By the way, it's advisable not to use regular expression functions for such basic tasks as converting set characters without pattern matching, because it takes up server strain. The str_replace() function is far more effective at this :)
 
Pejone said:
or you can do...

echo "<textarea>";
nl2br($var);
echo "</textarea>";
But that won't work because the textarea displays <br> as <br> and not new lines. You have to use
for a new line in a text area
 
Back
Top