replace break lines in string

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
fabrizzio
New php-forum User
New php-forum User
Posts: 10
Joined: Fri Dec 13, 2002 2:22 pm

replace break lines in string

Postby fabrizzio » Fri Dec 27, 2002 4:39 am

Hi forum,

i was trying to replace every enter press with a <br> in a text area, so when the user submits the form i'm using this:

$text = str_replace("\n","<br>",$textareavalue);

and the store it in a db, but when i see the fields the enter is still there! Php inserts the <br>s but i can't remove the enters.

thanks
fabrizzio

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Fri Dec 27, 2002 6:12 am

1) try to do "\n\r" or "\r\n"

2) $text=nl2br($textareavalue);

User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Thu Jan 02, 2003 3:07 am

Hi guys. I have the oposite problem. I have a php forum and it doesn´t replace enter key with <br>... it writes <br>.
I use: $text = str_replace("\n","<br>",$text);. In my case, i have already try the way u say Pejone, but it dosn´t work. I don´t know why it doesn´t work. My shoutbox have the same code, works with a form and tables...but works!
Last edited by gesf on Sun Mar 07, 2004 11:53 am, edited 1 time in total.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Jan 02, 2003 3:22 am


User avatar
gesf
Moderator
Moderator
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Postby gesf » Thu Jan 02, 2003 5:46 am

hey Pejone thanks,but i´d try all those examples but nothing. It doesn´t work. I don´t know what to do! I´ll keep trying!

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Thu Jan 02, 2003 5:52 am

show me your script (is that posible)

mynmonic
New php-forum User
New php-forum User
Posts: 18
Joined: Tue Nov 26, 2002 3:35 am
Location: Hong Kong
Contact:

Postby mynmonic » Fri Apr 04, 2003 8:54 am

I have the same problem when using nl2br(), the <br> is inserted but the return character doesn't removed. It works with str_replace("\r\n","<br>",$textarea).

I wonder what \r\n means? I don't see this combination for nl to br conversion in books, and why nl2br() can't actually help?

Could you tell me please?

User avatar
Skeletor
New php-forum User
New php-forum User
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio
Contact:

Postby Skeletor » Fri Apr 04, 2003 11:41 am

$string = ereg_replace("(\r\n|\n|\r)", '<br>', $string);


Return to “PHP coding => General”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 2 guests