prinft - 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
allelopath
Forum Commoner
Posts: 34
Joined: Tue Mar 16, 2004 5:21 am

prinft - nl2br

Post by allelopath »

I have these 2 lines:

printf ("id: %s Date: %s First Name: %s Last Name: %s\n",
$row[0], $row[1], $row[2], $row[3]);
print ("\n");

the newlines don't work.
i see there is a function nl2br to convert newlines to <br>
how do i use this?
Goowe
Forum Commoner
Posts: 94
Joined: Mon Mar 15, 2004 9:51 am
Location: Southeast Alaska

Post by Goowe »

before each of your \n thingers put the <BR> ;)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

allelopath wrote:the newlines don't work.
If you use Windows, it shouldn't.

Windows seperates the lines like so: \r\n

So try that, if not, do what I like to do and simply add <br> (or <br />). It's a bit more universal than line breaks. ;)
allelopath wrote:i see there is a function nl2br to convert newlines to <br>
how do i use this?
This is mainly used for changing line breaks in submitted data (such as this reply box in the forum, that I'm currently typing in). If you run a field such as $_POST['messagebox'] through [php_man]nl2br[/php_man](), every instance that someone hit enter within that box, the function will replace it with <br>. More info at the manual page.
Note: Starting with PHP 4.0.5, nl2br() is now XHTML compliant. All versions before 4.0.5 will return string with '<br>' inserted before newlines instead of '<br />'.
allelopath
Forum Commoner
Posts: 34
Joined: Tue Mar 16, 2004 5:21 am

Post by allelopath »

thanks for the comments
Post Reply