Roy766 Posted May 24, 2008 Share Posted May 24, 2008 I'm trying to make a line break in my php echoes...and it's not working... All my google and yahoo searches are telling me to use echo '\n'; ...but that just puts "\n" between the lines... Help! Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/ Share on other sites More sharing options...
947740 Posted May 24, 2008 Share Posted May 24, 2008 If you want an html line break: <br />. Otherwise, I am not quite sure what you are asking. However, you could try double-quotes. Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548662 Share on other sites More sharing options...
Roy766 Posted May 24, 2008 Author Share Posted May 24, 2008 Let me give an example with my previously corrected script: <?php $sfcost = $_REQUEST['swordfootmen'] * 3; $lfcost = $_REQUEST['lancefootmen'] * 3; $mswcost = $_REQUEST['mountedswordsmen'] * 5; $mlwcost = $_REQUEST['mountedlancemen'] * 5; $hcost = $_REQUEST['horses']; $totalcost = $sfcost + $lfcost + $mswcost + $mlwcost; $sfatk = $_REQUEST['swordfootmen'] * 2; $lfatk = $_REQUEST['lancefootment'] * 2; $mswatk = $_REQUEST['mountedswordsmen'] * 4; $mlwatk = $_REQUEST['mountedlancemen'] * 4; $hatk = $_REQUEST['horses']; $totalatk = $sfatk + $lfatk + $mswatk + $mlwatk + $hatk; $compatk = rand(10, 150); if ( $totalatk > 150 ) { echo "You spent too much money!"; } else { echo "Your total attack force is " . $totalatk; } echo 'The computers total attack force is ' . $compatk; if ( $compatk > $totalatk ) { echo 'Sorry, the computer wins...'; } else { echo 'You win! Congratulations!'; } ?> (Don't try just executing that. Requires the HTML to function...) When you win, you get: Your total attack force is ---The computers total attack force is ---You win! Congratulations! Exactly like that. All on one line. I'd like it with some line breaks inbetween there. Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548664 Share on other sites More sharing options...
947740 Posted May 24, 2008 Share Posted May 24, 2008 Use < br / >; instead of \n. *Without the space inbetween the < and b (The website will not let me use the entity.) Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548667 Share on other sites More sharing options...
Roy766 Posted May 24, 2008 Author Share Posted May 24, 2008 Do you mean to put that in an echo...? Or just throw it in the code? Cuz either way it still doesn't seem to work... Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548668 Share on other sites More sharing options...
947740 Posted May 24, 2008 Share Posted May 24, 2008 You should be able to put it in the echo, just like any other HTML code. E.G. else { echo "Your total attack force is " . $totalatk . "<br />"; } echo 'The computers total attack force is ' . $compatk . "<br />"; if ( $compatk > $totalatk ) { echo 'Sorry, the computer wins... <br />'; } else { echo 'You win! Congratulations! <br />'; } Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548669 Share on other sites More sharing options...
serverman Posted May 24, 2008 Share Posted May 24, 2008 also you could add else { echo "Your total attack force is <strong> " . $totalatk . "</strong><br />"; } echo 'The computers total attack force is ' . $compatk . "<br />"; if ( $compatk > $totalatk ) { echo '<font color ="FF0000">Sorry, the computer wins... </font><br />'; } else { echo '<font color="0000FF">You win! Congratulations!</font> <br />'; } just to add some color in there Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548671 Share on other sites More sharing options...
947740 Posted May 24, 2008 Share Posted May 24, 2008 Why would you want it to look good? Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548673 Share on other sites More sharing options...
haku Posted May 24, 2008 Share Posted May 24, 2008 If you want a linebreak in the display that you see in the browser, as others have mentioned, you want to use <br /> But if you want a linebreak in your source-code output, you can use PHP_EOL Using this, it will add a line break into the source code, making your source code easier to read. Link to comment https://forums.phpfreaks.com/topic/107031-line-break-in-php/#findComment-548677 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.