How to create a string that has new lines and tab characters in it?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm writting a script that produces html source code from form input.
My problem is that I want to format my html source with new lines and

So, I have a string that holds all the contents of the source and my
php script displays it by saying

echo '<form><textarea>'.$sourcestring.'</textarea></html>';  All of
that is working currectly except that I don't know how to get the tabs
and new lines in the string.

Here is what I have tried while assinging into the string:

/* This one works but I know there is another way, I hate leaving a php
string open and spanning multiple lines like this */
$sourcestring = '<div class="news" align=left>
    <div class="news_titlebar">
        <table width=100% border=0>
            <tr><td><u>Subject Line</u></td>
                <td align="right"><u>Thu, October the 20th 2005 at 7:23pm EST</td>
    <center><hr width=95% /></center>
    <div class="news_body">Body of the news post here

Notice that the '....' remains open for multiple lines of code and that
entire block there is a single assignment expression -- ewww, nasty.

/*This next way is how I tried to fix it, however, it didn't work.  The
\t and \n were output to the screen by the echo command.  Meaning my
page actually had the backslash and the letters t and n riddled
throughout */
$string = '<div class="news" align=left>\n\t<div
class="news_titlebar">\n\t\t<table width=100%
border=0>\n\t\t\t<tr><td><u>'.'Subject Line'.'</u></td>\n\t\t\t\t<td
align="right"><u>'.'Thu, October the 20th 2005 at 7:23pm
width=95% /></center>\n\t<div class="news_body">'.'Body of the news
post here'.'\n\t<br>\n\t</div>\n</div>';

I've looked everwhere and all I can figure out is that the escape
characters for strings in php should be \n and \t however these aren't
working for me.  Like I said earlier, if I was to say echo '\n\t\n'; I
would literally end up seeing "\n\t\n" printed to the screen instead of
a new line, then a line with only a tab, then a new line.

Re: How to create a string that has new lines and tab characters in it?

Robizzle wrote:
Quoted text here. Click to load it

The escape characters only work if you quote the string with double  
quotes (") rather than single quotes (').

Have a read through this page for more information:

Site Timeline