• Home
  • About
  • Who Am I?
  •  

    PHP Code Cleaner and Indenter

    Online Code Cleaner Demo

    With six years of experience with PHP , I have been ‘blessed’ with working with code written by really lazy people , who just didn’t think it was important at all to indent their code or comment it or make the opening and ending curly braces align.

    And sometimes our favorite FTP clients would add God knows why those silly annoying empty lines and the code would keep getting bigger and bigger.

    And I am sure that I am not alone in my frustrations.

    That is why is am writing this script which will try to take care of all that.

    Basically it will try to achieve the following goals:

    • Indent your code with tabs.
    • Put a comment block at the start of class definitions or functions.
    • Provide you with the facility to align curly brackets.
    • Remove unwanted lines from the code.
    • Put some spacing in blocks for improved readability.
    • Replaces short open tags with proper <?php tags
    • If a PHP block contains only one line , it will put the whole block in one line to improve readability.

    Please provide your valuable feedback to improve this script. I will be soon releasing a full script which will clean the code in all PHP files in a directory. Stay tuned!

    Online Code Cleaner Demo


    13 Responses to “PHP Code Cleaner and Indenter”

    1. Web 2.0 Announcer Says:

      PHP Code Cleaner and Indenter

      […][…]

    2. Arif Says:

      Great. I’ve looked for something like this befoe but not found a really satisfactory tool. This looks really good on the demo. Might be nice to have the before and after kb data on display.

    3. A K Nirala Says:

      Its cool man,

      But is it not that many editors provide a much better indentation.

    4. David Hunt Says:

      Brilliant - when will you provide a downloadable version?

    5. Bilal Ahmed Says:

      Sab!
      you rocks

    6. jv Says:

      Perfect tool! true!

    7. Richard Fairthorne Says:

      Can’t wait for the batch version download. I need a command prompt driven version.. with a shebang at the top and simple command line parsing.

      The second I can do:

      # phpcc -R *.php

      or similar, I’ll be buying you something on your amazon wishlist.

    8. John D Says:

      I find that the following works well using Vim:

      Open PHP file in Vim
      :source $VIMRUNTIME/indent/php.vim
      gg=G

      The final command indents the whole file. If you just want to indent a section of the file, visually select the desired section and press ‘=’.

    9. m Says:

      Excellent Tool! Thanks :)

      ————————————————–

      just to point out an warning on your homepage:

      Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/dphp/public_html/wp-content/plugins/BAStats/BAStats_logger.php on line 114
      M

    10. unomi Says:

      Hi, nice script, but.. whats up with replacing [0] with [305] ?

    11. gigamaster Says:

      Useful tool with a nice and clean interface.
      Hope to get the same result with code ^^
      and give it 5 stars

      Cheers

    12. unomi Says:

      Cheers for the fix Sab, now if only i could plug it into eclipse ;)
      hint hint nudge nudge

      Happy Hacking

    13. Shankar Says:

      hi,

      great tool.

      minor error

      $test= (isset($_POST[’test’]) ? clean($_POST[’test’]) : ”);

      becomes

      $test= (isset($_POST[’test’]) ? clean($_POST[’test’]) :
      ”);

    Leave a Reply