Jump to content


Photo

just weird


  • Please log in to reply
4 replies to this topic

#1 Mantis_61

Mantis_61
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 23 July 2006 - 11:54 PM

Hello readers,
I don't know if anyone can solve this without sitting behind my machine but I'm tripping over my shoe laces here. This is all so simple but still won't work!
my \n to break a line never works. I've tried with print() and echo?
I'm using php5.1.1 on Windows and can't figure it out. Is this bad syntax?...
echo "let's break \n it down!"
I've also tried...
echo "lets try this then \r\n STILL NOTHING!"
The escape isn't displayed but my line doesn't break either?
I've had other weird things cause errors in the past.
I've also tried uninstalling and reinstalling the engine as well as the server.
Is this an OS or server issue?
Sorry for posting something so minor but it has become a problem.


#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 24 July 2006 - 12:49 AM

How are you viewing this? Through a browser? \n does not effect the html output, view the source (right click) to view the output of....

echo "lets try this then\n STILL NOTHING!"


#3 scs

scs
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts
  • LocationUSA

Posted 24 July 2006 - 12:53 AM

Well I don't know your background knowledge of php/html. so excuse me if i'm obvious.

when you do this:
echo "let's break \n it down!"

you will see this in the browser.

let's break  it down!

But your code will be:

let's break
it down!

If you get where I'm going. I think thats your problem. If you are trying to breakline with \n you wont see it in the browser. So you need br tag. I hope thats what you were trying to do. If not explain a little more of what you want your end result to be.

#4 Mantis_61

Mantis_61
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 24 July 2006 - 11:50 AM

I guess that explains that. I was trying to use it for an easier type up vs. using html. As far as my computer background that goes back about 2 years of on and off recreational reading. Still venturing out to the older stuff and the UNIX basis for reference. Thanks for the answer. 

#5 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 24 July 2006 - 11:51 AM

This is becuase web browsers ignores whitespace characters, \n \r etc, howver in actuall fact they are still there, but in your source, right click view source.
The way around this to use nl2br which will conver line breaks/carriage returns in html line break (< br />), which the browser will not ignore. Heres a few examples:
<?php

// our demo string:
$str = "This line\n has line breaks and \rcarriage \n\n\nreturns!";

// this wont display the line breaks/carriage returns
echo $str;

echo "<br /><br />";

// however this will:
echo nl2br($str);

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users