News:

Join the Facebook Fan Page.

Main Menu

question about echo

Started by CokeCan, June 16, 2005, 08:34:04 PM

Previous topic - Next topic

CokeCan

One question, if I have got a variable that is something like this:
Quote$something = "hello,
how are you?";
But when I show it it shows everything in the same line, something like "hello, how are you?". What can I do to show it like it is? (in 2 lines)

JayBachatero

Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

CokeCan

but how can I put it? the variables are in the databse

Christian A. Herrnboeck

you can do this...

$something = str_replace(',',,\n',$something);

However, this requires there to be a , after the word... it'll then split, and put it down one line.

I believe that's the right order of the str_replace function.... Haven't used it in a while :D

-Christian


Farmers:Producing food for the world!

CokeCan

thanks but not all of them have got a ",", is it posible to add a "<br>" when the line ends?

rudoka

$something str_replace('\n','<br />',$something);


   The echo outputs HTML code, where so the \n character makes no sense. So you have to use <br>. If you are storing a text in the database which you will only use to display it on webpages, then probably the best solution is to make the change before putting it in the database.

Rudolf

CokeCan

I fixed it using nl2br
$something2=nl2br($something);
Thanks everybody :)

Advertisement: