PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
techkid
Forum Commoner
Posts: 54 Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives
Post
by techkid » Sun Mar 06, 2011 11:12 am
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.
litebearer
Forum Contributor
Posts: 194 Joined: Sat Mar 27, 2004 5:54 am
Post
by litebearer » Sun Mar 06, 2011 11:26 am
simply add a <br/> after each </li> in your php coding.
internet-solution
Forum Contributor
Posts: 220 Joined: Thu May 27, 2010 6:27 am
Location: UK
Post
by internet-solution » Mon Mar 07, 2011 6:30 am
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';
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Mon Mar 07, 2011 9:16 am
It's actually \r\n, but even \n would suffice.
Better yet, use PHP's new line constant, PHP_EOL.