Manfred62 Posted August 9, 2013 Posted August 9, 2013 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.
Macrura Posted August 9, 2013 Posted August 9, 2013 maybe this? <?php echo $page->adresse_detail . "<br />\r\n"; ?> or this? <?php echo $page->adresse_detail . '<br />' . PHP_EOL; ?>
Manfred62 Posted August 9, 2013 Author Posted August 9, 2013 thanks for taking a look at this. Tried both versions but they also don't work. Hmm, strange..
kongondo Posted August 9, 2013 Posted August 9, 2013 Btw, do you really need both <br/> and \n? Don't they accomplish the same thing (the latter without being output on the screen)?
Manfred62 Posted August 9, 2013 Author Posted August 9, 2013 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?
SiNNuT Posted August 9, 2013 Posted August 9, 2013 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 />
Manfred62 Posted August 9, 2013 Author Posted August 9, 2013 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.
n0sleeves Posted August 10, 2013 Posted August 10, 2013 maybe this will help? http://php.net/manual/en/function.nl2br.php Take a close look especially at the comments. Hope that helps!
Manfred62 Posted August 10, 2013 Author Posted August 10, 2013 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..
Craig Posted August 10, 2013 Posted August 10, 2013 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. 3
ryan Posted August 10, 2013 Posted August 10, 2013 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now