Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

replace break lines in string

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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
fabrizzio
New php-forum User
New php-forum User
 
Posts: 10
Joined: Fri Dec 13, 2002 2:22 pm

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

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

2) $text=nl2br($textareavalue);
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

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
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

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

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

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
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

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

show me your script (is that posible)
Oleg Butuzov
Last Samuray
Last Samuray
 
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

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?
mynmonic
New php-forum User
New php-forum User
 
Posts: 18
Joined: Tue Nov 26, 2002 3:35 am
Location: Hong Kong

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

$string = ereg_replace("(\r\n|\n|\r)", '<br>', $string);
Skeletor
New php-forum User
New php-forum User
 
Posts: 147
Joined: Tue Nov 19, 2002 7:47 am
Location: US, Ohio


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron