We help IT Professionals succeed at work.

converting \n to <br>

pagemastah
pagemastah asked
on
i have a form with a <textarea>. everytime the user provides message to the textbox and submits it, the form processor should convert the /n (carriage returns) to <br> then saves it to a flat-file database...

ive used this method but didn't work:

$message =~ tr/\n/<br>/;

this method should convert all \n to <br> but it doesn't...

please help... thanks in advance...
Comment
Watch Question

Commented:
$message =~ s/\n/<br>g;

Commented:
Oops, typo

$message =~ s/\n/<br>/g;

Author

Commented:
thanks for a quick response...

by the way, what does the /g stands for?

thanks!!!

Commented:
g stands for global.  Without it perl will only replace the first "\n" in the string with "<br>"

Explore More ContentExplore courses, solutions, and other research materials related to this topic.