Page 1 of 1

Using nl2br

Posted: Fri May 12, 2006 1:15 am
by SadnesS
Hello,

i have problem when i use nl2br function.

Here is the code to insert data to mysql database:

Code: Select all

$members = nl2br("$members");
Function wokrs great, but i have maked form that could use edit members field. So when i grab text from members table, it shows like this:

Code: Select all

Member<br />
Member2<br />
Member3<br />
So, how i can do it like this: When editing members table, list doesen't have <br /> functions at end.

Sorry my bad english!

Posted: Fri May 12, 2006 1:18 am
by Burrito
I assume you mean when you put the field values into a textarea? If so, then that's exactly what should happen.

nl2br() replaces line breaks with the html code (<br>).

Posted: Fri May 12, 2006 1:18 am
by RobertGonzalez
You will need to...

Code: Select all

<?php
$editmembers = str_replace(array("<br />","<br />","<br />"), array("\n","\r","\r\n"), $members);
?>
... to undo nl2br().

Posted: Fri May 12, 2006 1:24 am
by SadnesS
Thanks so quickly answers.

Yeah, i think that i have to use str_replace function. But first, i have to learn how i use it. :D

Posted: Fri May 12, 2006 1:25 am
by RobertGonzalez
Try clicking the links to the functions that are the code of my last post. They take you to the PHP manual page on str_replace.

Posted: Fri May 12, 2006 1:30 am
by SadnesS
Everah wrote:Try clicking the links to the functions that are the code of my last post. They take you to the PHP manual page on str_replace.
Yeah, i did figure that out. I don't use any functions that i doesen't know what they do, because i want to learn code PHP, not just copy/paste.

Posted: Fri May 12, 2006 2:01 am
by RobertGonzalez
That is an excellent way to learn how to code. Good luck with it.