New line

What is the new line symbol in HTML?

Is it
?

What does that do again?

I tried using it in my PHP and HTML but it doesn’t work in either?!

Debbie

newline characters

In HTML you can use <br>.

Writing innerHTML you might write
var build='<p>First line<\/p>
<p>2nd line<\/p>
';

If you were to look at the string you have built, say using an alert(build); the
characters show the code in its correct position as follows:
<p>First line</p>
<p>2nd line</p>

Without the
the string would not break at the end of the </p> and would be one long line.

In PHP use nl2br() to convert new lines into the HTML equivalent.

I’m not getting this.

Here is my code…


<?php
	// Get Configuration settings.
	require('includes/config.inc.php');

	// Set page title.
	$page_title = 'About';

	// Get Header file.
	require('includes/header.html');
?>
<h3>About</h3>
<p>This website is about...</p>
<p>Apples</p>\
<p>Oranges</p>\
<p>Bananas</p>
<?php
	// Get Footer file.
	include ('includes/footer.html');
?>

If I take out my two
's
then one line in the View Code I get…

<p>Apples</p><p>Oranges</p><p>Bananas</p>

If I leave them in, then I still get one line in the View Code…

<p>Apples</p><p>Oranges</p><p>Bananas</p>

and in my web page I get…

Apples
Oranges
Bananas

Debbie

In straight HTML the
is not required as the </p> will automatically break when the code is rendered on the page.
The code sample you have provided needs to look like this.
<p>This website is about…</p>
<p>Apples</p>
<p>Oranges</p>
<p>Bananas</p>

I’m not getting this.

<p>s are block-level elements and so don’t need a new line between them. If you want to display something that normally appears inline in html on a new line then you can use <br> or the xhtml <br />

No.

Here is the answer…


<?php
	echo "\
<p>Apples2</p>\
<p>Oranges2</p>\
<p>Bananas2</p>\
";
?>

That will give me…


<p>Apples2</p>
<p>Oranges2</p>
<p>Bananas2</p>

in my View Page Source.

As far as the web page itself, right, I only need <p> or <br> to create page breaks in the web page itself.

I was asking about
to format my HTML.

Thanks,

Debbie

The answer is in the the link I posted in my first post in this thread.

For PHP to interpret
as new line it needs to be inside of “” and output using an echo or print command.

To get a new line in HTML simply start a new line.

I’m not saying this to be mean, but the link says (if you can find it in all that clutter):

This page examines the nuances of escape characters used in C and Java program coding.

If you dig through you can find a line talking about escaping dollar signs in PHP, but… Debbie already knows that
is the newline character she needs.

And I’m not saying the information on the page doesn’t have value, but…
<p>
<img src=“http://merc.tv/img/wav.gif” width=“16” height=“16” border=“0”>
<a href=“sounds/poolbreak.wav”>
Sound: Pool balls breaking</a>
<p>
I went ARGLEBLARGLEAAAAAACKpbth!

Stephen seems to have pointed out why Deb’s original
weren’t working. I didn’t see anything about quote marks in PHP on that page (but I may have missed it).

Thank you!! :lol:

At any rate, I figured things out, and Felgall’s comments help also.

Thanks,

Debbie

I think it was mentioned already, but since that is static markup there is no need for
. Simply format the html as you want it.

<?php
	// Get Configuration settings.
	require('includes/config.inc.php');

	// Set page title.
	$page_title = 'About';

	// Get Header file.
	require('includes/header.html');
?>
<h3>About</h3>
<p>This website is about...</p>
<p>Apples</p>
<p>Oranges</p>
<p>Bananas</p>
<?php
	// Get Footer file.
	include ('includes/footer.html');
?>

cheers,

gary

As you probably know now /n does nothing in html or php.
You can use <br> 's but they are recommended not for styling or layout, but for breaking lines in content; such as, multiple stanzas in a poem.

Allan P, what is the two different slashes in the closing paragraph? <\/p> ?

I have seen this, but always wonder what is its use or its purpose?

Thanks in Advance,
Team 1504

Wrong.

The
creates a carriage return in your HTML when you view the page source.

(That was the whole purpose for this thread even though several people missed that.)

If you look above, you’ll see how I properly figured out the syntax to use
in my PHP to display HTML the way I wanted in the HTML output.

Allan P, what is the two different slashes in the closing paragraph? <\/p> ?

I have seen this, but always wonder what is its use or its purpose?

Thanks in Advance,
Team 1504

It is an escape character for the forward slash…

Debbie

Team: Debbie wanted to keep her source code from becoming one long unreadable line when you View Source on her web page. So not <br> style newlines on the web page, just in the source.

Debbie, does Gary’s solution work? Manually making the breaks without characters in your PHP?

XHTML considers the forward slash to be an end marker, so when writing HTML with JavaScript the forward slashes should be preceded with an escape character (“\”, backward slash).

If your HTML code looks like this…


<p>One</p><p>Two</p><p>Three</p>

<p>Four</p>
<p>Five</p>
<p>Six</p>

then the Page Source will look like this…


<p>One</p><p>Two</p><p>Three</p>

<p>Four</p>
<p>Five</p>
<p>Six</p>

and your screen output will look like this…

One

Two

Three

Four

Five

Six

*************************

If your PHP code looks like this…

<?php
	echo "<p>Seven</p><p>Eight</p><p>Nine</p>

<p>Ten</p>
<p>Eleven</p>
<p>Twelve</p>";
?>

then the Page Source will look like this…


<p>Seven</p><p>Eight</p><p>Nine</p>

<p>Ten</p>
<p>Eleven</p>
<p>Twelve</p>

and your screen output will look like this…

Seven

Eight

Nine

Ten

Eleven

Twelve

So apparently the carriage returns do work in the PHP code.

*************************
HOWEVER

If your PHP code looks like this…


<?php
	echo "\
<p>Break</p>\
<p>This</p>\
<p>Single</p>\
<p>Line</p>";
	echo "\
Up\
Into\
Parts\
";
?>

then the Page Source will look like this…


<p>Break</p>
<p>This</p>
<p>Single</p>
<p>Line</p>
Up
Into
Parts

and your screen output will look like this…

Break

This

Single

Line
Up Into Parts

So using the
does have its place in your tool-belt when you need to pretty-up your HTML code that is created by your PHP code.

Debbie

Yes, I agree if you are using PHP then sometimes you may use
for the newline if you are using string and echo for pretty format of the source code output.

For example:

echo ("<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>\
");

Is there any particular reason why you put ( ) around the string?

echo "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>\
";

works just as well and is two characters less.

One thing you do need to watch out for with that particular statement is that PHP short tags are not turned on. If it is turned on then you’d need to write that statement like this to avoid errors:

echo "<"."?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?".">\
";