Break lines / paragraphs

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
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Break lines / paragraphs

Post by dwfait »

Hi. In my script people can PM each other, and administrators can post news. But, whenever i put a new line in, when you read it after you have posted it, there isnt a new line, it just continues. How can i put a new line where i put a new line and stuff?
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

this is the function you'll want to use:

http://us2.php.net/manual/en/function.nl2br.php
dwfait
Forum Contributor
Posts: 113
Joined: Sun Aug 01, 2004 10:36 pm

Post by dwfait »

Thanks, it worked.
Getran
Forum Commoner
Posts: 59
Joined: Wed Aug 11, 2004 7:58 am
Location: UK
Contact:

Post by Getran »

i think i did it a different way once, using ereg_replace(). something like this:

$text = ereg_replace("\n","<br>",$text);

anyway, as he said it worked so i dunno why i'm posting this :roll:
User avatar
tim
DevNet Resident
Posts: 1165
Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio

Post by tim »

Getran, you could use regular expressions to achieve this, but when theres a function designed for it, why not use it?

Envoking the regEx engine when you dont need too is a bad practice.
Post Reply