Removing the closing PHP tags from Eclipse PDT templates

Dec 9, 2008

UPDATE: I submitted this as a bug report for Eclipse PDT, and it's now part of the latest release!

Like many PHP developers who use Eclipse PDT, your first step after creating a new PHP file is probably to remove the closing ?> tag that Eclipse puts in it for you. Today I did those same three keystrokes (or more if you don't use keyboard shortcuts) to remove the damn closing PHP tag (whose absence is part of many coding standards), and decided to never do it again manually. The solution is quite simple:

  • Open the eclipse preferences through the menu (exact location varies between operating systems).
  • Select PHP >> Templates in the navigation on the left.
  • On the right, select the New Simple PHP file template and click edit.
  • Change the pattern from

<?php ${cursor} ?>

to

<?php ${cursor}

  • Ok, Ok again, and you're done!