Quick Search for:  in language:    
   Code/Articles ╗ |  Newest/Best ╗ |  Community ╗ |  Jobs ╗ |  Other ╗ |  Goto ╗ | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
PHP Stats

 Code: 66,306 lines
 Jobs: 13 postings

Sponsored by:


You are in:


Latest Code Ticker for PHP.
Simple Forum
By Chas Pardee on 6/20

Click here to see a screenshot of this code!Squiggles
By Chas Pardee on 6/20

(Screen Shot)

photo guide
By Chas Pardee on 6/20

Download Script
By YANP on 6/19

Logging IP's
By Klaus Andersen on 6/18

Server Uptime
By Martin C. Conniffe on 6/15

Send a Page/Link to a Friend
By rae the coder on 6/15

Display contents of a directory and include it in a text area
By Daniel Friedman on 6/15

By Alberto Sartori on 6/13

Click here to put this ticker on your site!

Add this ticker to your desktop!

Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites


Proper Indentation


Submitted on: 3/5/2001 8:39:35 PM
By: Steve Oliver  
Level: Beginner
User Rating: By 6 Users
Compatibility:PHP 3.0, PHP 4.0

Users have accessed this article 6672 times.
(About the author)
     Teaches the basics of Proper Indentation in your php source.

Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
I think it is a basic coding standard to Indent each function, loop, etc. This not only helps others that may be working with your source, But it also helps when you go back and look at your source. Below are some examples of right and wrong.

wrong way:
should be:

wrong way:
if($blah==""){echo $blah;}else{echo "none";}}

should be:
   echo $blah;
   echo "none";

wrong way:
function doit($var){
return $var;}

should be:
function doit($var)
 return $var;

I think you get the basic Idea. Although it may seem long and drawn out, trust me, it will help you in the long run.


Other 4 submission(s) by this author


Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
Other User Comments
3/8/2001 10:33:35 PM:Shaun
Steve is right, although it may seem like more coding up front, it'll help you later when you need to read your code. And if you're publishing code that someone else will be reading or using, it becomes even more important that it's formatted in an easy-to-read manner. Another common convention is to place the opening brace on the same line as the start of the function definition, loop call, etc: while(1){ echo
Keep the Planet clean! If this comment was disrespectful, please report it:

9/7/2001 7:34:59 AM:Matthias
I agree to Shaun, that there is not only one way to format source code. I use the same formatting as Shaun <pre> function xyz() { print
Keep the Planet clean! If this comment was disrespectful, please report it:

9/13/2001 9:58:43 PM:Rob Loach
I have a habbit of doing: if($var==""){ $var="false"; } (having the first bracket on the first line) I find that this is very good. I know that it is neater to have the bracket on a new line, but I really don't like to scrool up and down my code alot.
Keep the Planet clean! If this comment was disrespectful, please report it:

Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.


Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | PHP Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyrightę 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.