Jump to content

just weird


Mantis_61

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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. 
Link to comment
Share on other sites

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:
[code]<?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);

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.