Forum Moderators: coopster

Message Too Old, No Replies

displaying \t and \n in a browser

         

undream2

8:53 pm on Jun 16, 2009 (gmt 0)

10+ Year Member



Hi,

I am not a php pro.. And, I never had to come up with this solution..

I created a php code to parse, data from mysql.. Ok, it all works great.. The php output needs to be able to copy paste into a spreadsheet..

So, I need to TAB the text on the output, so I can copy paste into a spreadsheet,, and the spreadsheet recognizes the columns..

So I need the php code, to make the text to show the TABs and NEW LINES on the output.. Is there any?

Also, if someone says use the escape characters \t and \n, as a solution.. GRRR... This is the only information I can find on my problem.. They are just for looks(i think),, i've been on this problem for hours..

PLEASE HELP!

Robeysan

10:13 pm on Jun 16, 2009 (gmt 0)

10+ Year Member



undream2,
Do you know how to uses classes? I used this class I found over at phpclasses.org that creates csv's from mysql queries.

[phpclasses.org...]

janharders

10:20 pm on Jun 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you're probably sending html ...
either put

<pre></pre>

around the text that conains tabs and newlines or send a header indicating that the data that follows will be plain text. to do that, add
header("Content-type: text/plain");
at the top of your script (that is, before any other output is printed). If you do that, of course you cannot send html (well, you can, but it'll be shown, not interpreted).

undream2

12:35 am on Jun 17, 2009 (gmt 0)

10+ Year Member



janharders, thank you.. It worked just perfectly..

I knew it was going to be simple.. lol, I hate trying to figure out things for hours on hours, and it is something so simple.. lol

also, thanks robeysan.. I bookmarked that class.. Im sure, I'll use it someday..

jatar_k

3:07 pm on Jun 17, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



let me clarify a little as to why pre tags worked

using \t and \n is the correct way, but browsers do not display tabs and newlines, they only display html

If you view source of the page you would have always seen the correct tabs and newlines

the pre tag forced the browser to show the text as it is formatted without html

another option is you could create a file for them to save ;)