help regarding regular expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vb_123
Forum Newbie
Posts: 19
Joined: Wed May 21, 2008 2:16 am

help regarding regular expression

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: help regarding regular expression

Post by John Cartwright »

nl2br() converts newlines to line breaks for you
vb_123
Forum Newbie
Posts: 19
Joined: Wed May 21, 2008 2:16 am

Re: help regarding regular expression

Post 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.......
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: help regarding regular expression

Post by John Cartwright »

What have you tried? And why is it mandatory? Sounds silly.
vb_123
Forum Newbie
Posts: 19
Joined: Wed May 21, 2008 2:16 am

Re: help regarding regular expression

Post 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
Post Reply