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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.