colap Posted February 5, 2011 Share Posted February 5, 2011 Can't echo newline. <?php class Myclass{ public $var_one=100; public $var_two=400; function printvalues(){ echo 'Inside printvalues function\n'; echo '$var_one: '.$this->var_one.'\n'; } } $obj=new Myclass(); $obj->printvalues(); echo '$var_two: '.$obj->var_two.'\n'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/226758-simple-problemits-not-echoing-newline/ Share on other sites More sharing options...
kenrbnsn Posted February 5, 2011 Share Posted February 5, 2011 The \n isn't interpreted when enclosed in single quotes, use double quotes. This <?php echo '\n'; ?> will echo the string \n, while this <?php echo "\n"; ?> will produce a newline character. But the newline character isn't seen by the browser as a newline, for that you need to echo the <br> tag. Ken Quote Link to comment https://forums.phpfreaks.com/topic/226758-simple-problemits-not-echoing-newline/#findComment-1170158 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.