Jump to content

Recommended Posts

Posted

Tried to make the source (html) looking cleaner. In the code of a repeater template this doesn't work:

<?php echo "{$page->adresse_detail}<br />\n"; ?>

but this does work:

<?php echo "{$page->adresse_detail}\n<br />"; ?>

Could anyone explain this? I'm on Win7 and XAMMP.

Posted

maybe this?

<?php echo $page->adresse_detail . "<br />\r\n"; ?>

or this?

<?php echo $page->adresse_detail . '<br />' . PHP_EOL; ?>
Posted

of course there's no need for both. It's only cosmetics in the source.

But I'm wondering, why \n<br /> is working and <br />\n is not?

Posted

What does not work with your first line of code? I'm on Windows 7 as well and everything works as expected:

template:

<?php echo "{$page->title}<br />\n"; ?><?php echo "{$page->title}<br />\n"; ?>
<?php echo "{$page->title}\n<br />"; ?><?php echo "{$page->title}\n<br />"; ?>

output in 'view source', in IE, FF and Chrome, all the same:

title<br />
title<br />
title
<br />title
<br />
Posted

I only get the source without new line (first example):

title<br />title<br />title<br />title<br />

hmm, also tried different browsers. Still wondering, why the second example is working.

Posted

thanks for the link.

tested the following:

<?php echo nl2br("$page->adresse_detail\n"); ?>
// html output:
first line<br />next line<br />third line<br />

there's no need for the <br> tag, php does it.

But new line is only working inside a string. For example, this string shows a new line in the source:

<?php echo nl2br("$page->adresse_detail\n "); ?>
// html output:
first line<br />
 next line<br />
 third line<br />
 

always nice to learn something new..

Posted

The output of a template is ran through the PHP function trim(), which removes whitespace characters surrounding strings (start and end). \n is one of those characters.

  • Like 3
Posted
The output of a template is ran through the PHP function trim(), which removes whitespace characters surrounding strings (start and end). \n is one of those characters.

That's right. So if "{$page->adresse_detail}<br />\n" is literally the only thing being output by the template file, then that trailing "\n" will be stripped. But in the context of a larger HTML document, you wouldn't see the "\n" stripped. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...