You are here: Re: How to create a string that has new lines and tab characters in it? « PHP Programming Language « IT news, forums, messages
Re: How to create a string that has new lines and tab characters in it?

Posted by Juliette on 10/21/05 04:29

Robizzle wrote:
> 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
> tabs.
>
> 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>
> </tr>
> </table>
> </div>
> <center><hr width=95% /></center>
> <div class="news_body">Body of the news post here
> <br>
> </div>
> </div>';
>
> 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
> EST'.'</td>\n\t\t\t</tr>\n\t\t</table>\n\t</div>\n\t<center><hr
> 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.
>


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:
http://www.php.net/manual/nl/language.types.string.php

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация