Page 1 of 1

help regarding regular expression

Posted: Mon Jun 02, 2008 11:23 pm
by vb_123
i have a following code......
$msg=addslashes(str_replace("\n","<br>",$message))
message is here text area.

here using str_replace i am replacing newline("\n") with <br> and instead of str_replace i want to do this using regular expression preg_replace.so how will i do it.its urgent thanx in advance

Re: help regarding regular expression

Posted: Mon Jun 02, 2008 11:26 pm
by John Cartwright
nl2br() converts newlines to line breaks for you

Re: help regarding regular expression

Posted: Mon Jun 02, 2008 11:35 pm
by vb_123
Jcart wrote:nl2br() converts newlines to line breaks for you
i have to use preg_replace only.its mandatory so how can i do it using preg_replace.......

Re: help regarding regular expression

Posted: Tue Jun 03, 2008 12:18 am
by John Cartwright
What have you tried? And why is it mandatory? Sounds silly.

Re: help regarding regular expression

Posted: Tue Jun 03, 2008 12:53 am
by vb_123
its mandatory bcoz it is told to do with that only and i don't know how to do it with preg-replace thts why i am asking