1

Topic: \t\t\t\t\t ?!

I'm not a programmer. I have one PHP script that's full of this crap:

echo "\t\t\t\t" . '' . "\n";

What does \t\t\t\t and \n\t\t\t\t\t etc. do? Can I clean it up or is it essential?

Re: \t\t\t\t\t ?!

It inserts tabs in the source code. The part you posted is useless though.

3 (edited by Jansson 2007-04-01 18:02)

Re: \t\t\t\t\t ?!

\n = Newline Unix-style
\r\n = Newline Wndows-style
\t = Tab

Usually used to output indented code (that's easier to read).

4

Re: \t\t\t\t\t ?!

i've always been wondering as to what this code was for as well. So basically "\t\t\t\t" inserts 4 tabs?

Re: \t\t\t\t\t ?!

Yes

Re: \t\t\t\t\t ?!

It's there only to make the output pretty.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

7

Re: \t\t\t\t\t ?!

Thanks!

I'd rather have the input code looking pretty...

8

Re: \t\t\t\t\t ?!

Peter wrote:

Thanks!

I'd rather have the input code looking pretty...

Obviously not a web designer either then. Trying to understand the output using view source when everything has ended up in a heap or, even worse, on one line, is no joke.

Re: \t\t\t\t\t ?!

I agree in putting newlines in the code, but tabs is just a waste of perfectly good text imo. You can see what belongs where good enough, and with certain complex layouts you'd spend more time trying to get the tabs right than actually coding the backend.

Re: \t\t\t\t\t ?!

I have to agree with Paul: it's MUCH easier to read with proper newlines and tabbing. Just like with source code, tabbing makes it easier to see where certain tags begin/end

Re: \t\t\t\t\t ?!

I'm a little split on this myself actually. I do like the output to be pretty, but I have to agree, all those \n and \t in the code annoy the hell out of me.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: \t\t\t\t\t ?!

When I'm lazy I usually just end the php block and type the html as usual smile

13

Re: \t\t\t\t\t ?!

Rickard wrote:

I'm a little split on this myself actually. I do like the output to be pretty, but I have to agree, all those \n and \t in the code annoy the hell out of me.

The cleaner alternative of course is to not to echo markup in which case html can be written as a block with new lines and indents. The result should be tidy source and output. The exception being imploded arrays which would still require new lines and tabs. The downside of course is constant switching between php and straight html.

Re: \t\t\t\t\t ?!

Paul wrote:

The downside of course is constant switching between php and straight html.

Exactly. I'm not sure which I prefer.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

Re: \t\t\t\t\t ?!

I'd say the current way of doing it where we do one liners through echo, and multiple lines of html outside of php is the best way to go. It makes for much cleaner code and many times you don't want to output the html right away but store it in a variable, which force you to use php anyway smile

Re: \t\t\t\t\t ?!

When I'm just writing HTML, I indent decently. But when I'm outputting stuff like options in a select, I just can't be arsed to go count the tabs really. The source is readable enough to debug and such, and that's all I need really.