Jump to content

escape character newline \n tab \t not working


saiyen2002

Recommended Posts

I am relatively new php programmer, and seem to be stuck on something really simple. As I understant it, \t gives you a tab and \n give you a new line. However this does not seem to be the case. Can some one please help me, i am really stressing over this. I am using the following on Fedora linux

 

PHP 5.3.1

Apache/2.2.14

 

contents of file index.php

 

<?php

echo "hello \t world \n";

echo "hello \t universe \n";

?>

 

the out put of this code is

 

hello world hello universe

 

everything is on one line. Can somebody please help see the light!

If you view the source you will see the proper indentation / new lines. In order for the browser to see it you will need to put inside of a <pre> tag:

 

<?php
echo "</pre>hello \t world \n";
echo "hello \t universe \n</pre>";
?>

 

Browsers tend to hide those due to the fact that html can have a ton of tabs and new lines in it that are not meant to be displayed.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.