Page 1 of 1

PHP Adding a Line Break

Posted: Sun Mar 06, 2011 11:12 am
by techkid
Hello,

This is how my PHP code is written:

Code: Select all

         echo '<li'; if($page == "index.html") echo ' class="selected"'; echo '><a href="' .HOME_URL. '">Home</a></li>';
         echo '<li'; if($page == "about.html") echo ' class="selected"'; echo '><a href="' .ABOUT_URL. '">About</a></li>';
         echo '<li'; if($page == "portfolio.html") echo ' class="selected"'; echo '><a href="' .PORTFOLIO_URL. '">Portfolio</a></li>';
         echo '<li'; if($page == "contact.php") echo ' class="selected"'; echo '><a href="' .CONTACT_URL. '">Contact</a></li>';
and Here is the source code of my HTML:

Code: Select all

<li><a href="home">Home</a></li><li><a href="about">About</a></li><li><a href="portfolio">Portfolio</a></li><li><a href="contact">Contact</a></li>
It appears as 1 line, I want each <lI> to appear in a new line.

Any suggestions?

Thank you.

Re: PHP Adding a Line Break

Posted: Sun Mar 06, 2011 11:26 am
by litebearer
simply add a <br/> after each </li> in your php coding.

Re: PHP Adding a Line Break

Posted: Mon Mar 07, 2011 6:30 am
by internet-solution
It seems you want to keep your HTMl source code tidy. Use line break (\n\r) in php echo's. Example

Code: Select all

echo '<li'; if($page == "index.html") echo ' class="selected"'; echo '><a href="' .HOME_URL. '">Home</a></li>\n\r';

Re: PHP Adding a Line Break

Posted: Mon Mar 07, 2011 9:16 am
by John Cartwright
It's actually \r\n, but even \n would suffice.

Better yet, use PHP's new line constant, PHP_EOL.