Using nl2br

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
SadnesS
Forum Newbie
Posts: 5
Joined: Fri May 12, 2006 1:10 am

Using nl2br

Post 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!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post 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>).
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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().
SadnesS
Forum Newbie
Posts: 5
Joined: Fri May 12, 2006 1:10 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
SadnesS
Forum Newbie
Posts: 5
Joined: Fri May 12, 2006 1:10 am

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

That is an excellent way to learn how to code. Good luck with it.
Post Reply