PlagueInfected Posted November 28, 2009 Share Posted November 28, 2009 I've always had an issue with this kind of PHP <?php $scr = $_SERVER['SCRIPT_FILENAME']; echo '<ul>\n'; if ($scr == 'main.php') { echo '<li><a class=\"onpage\" href=\"/main.php\">main</a></li>\n'; } else { echo '<li><a href=\"/main.php\">main</a></li>\n'; } if ($scr == 'services.php') { echo '<li><a class=\"onpage\" href=\"/services.php">services</a></li>\n'; } else { echo '<li><a href=\"/services.php\">services</a></li>\n'; } if ($scr == 'portfolio.php') { echo '<li><a class=\"onpage\" href=\"/portfolio.php\">portfolio</a></li>\n'; } else { echo '<li><a href=\"/portfolio.php\">portfolio</a></li>\n'; } if ($scr == 'blog.php') { echo '<li><a class=\"onpage\" href=\"/blog.php\">blog</a></li>\n'; } else { echo '<li><a href=\"/blog.php\">blog</a></li>\n'; } echo '</ul>\n'; ?> when it's outputting in HTML, is displays \n and does not do a line break. I don't want to use the line break either to display my list properly either. Link to comment https://forums.phpfreaks.com/topic/183224-newline-n-not-working-for-me/ Share on other sites More sharing options...
mattyvx Posted November 28, 2009 Share Posted November 28, 2009 Use the double quote with your echo and it should work. eg. echo "<li><a href=\"/services.php\">services</a></li>\n"; Link to comment https://forums.phpfreaks.com/topic/183224-newline-n-not-working-for-me/#findComment-967017 Share on other sites More sharing options...
Mchl Posted November 28, 2009 Share Posted November 28, 2009 Use: nl2br Link to comment https://forums.phpfreaks.com/topic/183224-newline-n-not-working-for-me/#findComment-967019 Share on other sites More sharing options...
mattyvx Posted November 28, 2009 Share Posted November 28, 2009 Thats what i'd use, or just hard code the <br /> 's in but... I don't want to use the line break either to display my list properly either. and nl2br will output <br /> after each item right? Link to comment https://forums.phpfreaks.com/topic/183224-newline-n-not-working-for-me/#findComment-967021 Share on other sites More sharing options...
Mchl Posted November 28, 2009 Share Posted November 28, 2009 My bad. He just wanted to align HTML properly, so your advice is enough. Link to comment https://forums.phpfreaks.com/topic/183224-newline-n-not-working-for-me/#findComment-967024 Share on other sites More sharing options...
mattyvx Posted November 28, 2009 Share Posted November 28, 2009 yes, as the items are part of an Unordered list they will break onto a new line anyway. However!!!!..... If you assign a CSS class "Float" to your list it will display horizontally and you will need to use the nl2br() suggestion to display any vertical items. Link to comment https://forums.phpfreaks.com/topic/183224-newline-n-not-working-for-me/#findComment-967032 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.