tab character to whitespaces

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
julian_lp
Forum Contributor
Posts: 121
Joined: Sun Jul 09, 2006 1:00 am
Location: la plata - argentina

tab character to whitespaces

Post by julian_lp »

I need to keep the format after replacing tabs to withespaces...

Is there a recommended way to replace the tab character with white spaces in order to save the original format ?

Rephrasing the question would be... how many spaces does a Tab character involves? I guess it is not always the same number though...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: tab character to whitespaces

Post by volka »

julian_lp wrote:I guess it is not always the same number though...
That is correct and therefore the answer to your question is: it depends ;)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Ya, it depends, but I think in most cases it's 4. I've only ever seen 4 & 2 as defaults in programs.

Probably the easiest way to do it would be:

Code: Select all

$new_format = str_replace("\t",'    ',$old_format);
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply