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
replace break lines in string
Moderators: egami, macek, gesf
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
1) try to do "\n\r" or "\r\n"
2) $text=nl2br($textareavalue);
2) $text=nl2br($textareavalue);
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!
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.
Sincerely,
Gonçalo "gesf" Fontoura
gesf.org | sessionstart.com | urlms.com
Gonçalo "gesf" Fontoura
gesf.org | sessionstart.com | urlms.com
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
go here. read user comments.
http://www.php.net/manual/en/function.nl2br.php
btw , this link
http://www.php.net/manual/en/function.wordwrap.php
http://www.php.net/manual/en/function.nl2br.php
btw , this link
http://www.php.net/manual/en/function.wordwrap.php
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!
Sincerely,
Gonçalo "gesf" Fontoura
gesf.org | sessionstart.com | urlms.com
Gonçalo "gesf" Fontoura
gesf.org | sessionstart.com | urlms.com
-
- Last Samuray
- Posts: 824
- Joined: Sun Jun 02, 2002 3:09 am
show me your script (is that posible)
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?
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?
$string = ereg_replace("(\r\n|\n|\r)", '<br>', $string);