New Line Question

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
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

New Line Question

Post by Sevengraff »

Ok, I made a simple text-based news script, and it keeps news posts as one line on a text file. This means that if i hit return in the text area when i submit the news, it will mess everything up. Is there anyway I can not have this happen?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

i wish that helped.
nl2br does replace a new line with a <br />, wich is helpful, except that it puts the remaing text on a new line. and with str_replace, i dont know what to replace. what is the character?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

take a look at the user contributed notes
really do as solutions already habe been provided there
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

just make a new function then, and apply it to the input

say $post contained the information you wanted on one line, then just do

Code: Select all

str_replace("\n", "<br/>", $post);
then that would work. but what i'd do, is right before it's printing, cause the source would be really cluttered if everything was on one line is:

Code: Select all

echo str_replace("<br/>", "/n<br/>", $post);
Post Reply