coder13 Posted March 31, 2011 Share Posted March 31, 2011 I am trying to do a simple return between two strings in a php block. All i get is a blank page when i insert the echo /n line.... what am i doing wrong? this is my code: <?php $str = "my string"; $str1 = "my other string"; echo $str; echo /n; echo $str1; ?> Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/ Share on other sites More sharing options...
KevinM1 Posted March 31, 2011 Share Posted March 31, 2011 The newline character is a string literal, which means it must be placed in quotes. It's also \n, not /n. Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/#findComment-1194937 Share on other sites More sharing options...
coder13 Posted March 31, 2011 Author Share Posted March 31, 2011 thanks for the reply but it is still not working. <?php $str = "my string"; $str1 = "my other string"; echo $str; echo "\n"; echo $str1; ?> this returns: my string my other string i want it to return: my string my other string Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/#findComment-1194956 Share on other sites More sharing options...
KevinM1 Posted March 31, 2011 Share Posted March 31, 2011 The newline character is working in regard to your generated output (look at your source code in the browser). The 'problem' is that you're looking at it with the browser. To a browser, an HTML line break element (<br>) is what will make a new line visible on the screen. In other words, your generated code is: my string my other string But since browsers ignore white space, it's being displayed as: my stringmy other string To make it look right in the browser, swap \n for <br> Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/#findComment-1194960 Share on other sites More sharing options...
kenrbnsn Posted March 31, 2011 Share Posted March 31, 2011 The "\n" is not the newline on the browser display. To the browser, that character is another whitespace character. To get a newline on the browser, you need to use the HTML tag "<br>". If you had looked at the source, you would have seen the newline between those strings: <?php $str = "my string"; $str1 = "my other string"; echo $str; echo "<br>"; echo $str1; ?> or <?php $str = "my string"; $str1 = "my other string"; echo "$str<br>$str1"; ?>[code] Ken Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/#findComment-1194962 Share on other sites More sharing options...
coder13 Posted March 31, 2011 Author Share Posted March 31, 2011 thanks for the clarification.... think i have it now.... Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/#findComment-1194964 Share on other sites More sharing options...
co.ador Posted March 31, 2011 Share Posted March 31, 2011 <br/> tags will break a line jumping to the next line. Quote Link to comment https://forums.phpfreaks.com/topic/232286-new-to-php/#findComment-1194969 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.