Finding PHP Short Tags

There are a number of ways to escape between PHP and output (usually HTML) mode. Personally I recommend sticking with the traditional <?php style. One method that can cause problems is the so called ‘short tag’ style – <? and I recommend avoiding it.

So how do you know if there are PHP short tags being used some where in your code? I use grep to search for them: grep -rn "<?[^p]" *

No related posts.

This entry was posted in Posts and tagged , . Bookmark the permalink.

6 Responses to Finding PHP Short Tags

  1. Ant says:

    I use <?php tags, but what is problem with shorttags? I never found explanation.

  2. Thanks for the tip, Joseph. Very useful—I’ve added it to my arsenal of theme testing checks.

  3. Aaron Pepper says:

    I like to use short tags for personal and client work, when I know I have full control of the hosting environment. I’ll use full php tags for public and open source code.

    It kinda sucks that short tags aren’t enabled by default. is so much nicer than . Less typing, and readability is better.

    • Joseph Scott says:

      The situation where you just need to do a simple echo would be nicer, but could potentially be accomplished with <?php= $some_var ?> – hopefully PHP core will support that syntax one day.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>