Opening PHP Tags Not Being Recognised

September 20th, 2010 - Posted by Steve Marks to PHP, Web Development.

A block of PHP code can be started using an opening tag of either ‘<?php’ or ‘<?’. The latter, also known as a short tag, is generally not recommended any more due to the widespread use of XML and can result in the server parsing the wrong code in the wrong context.

For older applications built prior to the explosion of XML on the web that contain the short tag, or for people who prefer coding PHP using this format, you may at some point run into a scenario where the opening tag is not recognised and, as a result, the PHP code is output as plain text onto the page. This will more than likely be the case following a move or upgrade of your server.

To get around this you need to look into your php.ini at about line 200 where you will see the following:

; This directive determines whether or not PHP will recognize code between
; <? and ?> tags as PHP source which should be processed as such. It's been
; recommended for several years that you not use the short tag "short cut" and
; instead to use the full <?php and ?> tag combination. With the wide spread use
; of XML and use of these tags by other languages, the server can become easily
; confused and end up parsing the wrong code in the wrong context. But because
; this short cut has been a feature for such a long time, it's currently still
; supported for backwards compatibility, but we recommend you don't use them.
; Default Value: On
; Development Value: Off
; Production Value: Off
short_open_tag = Off

Simply turn the ‘short_open_tag’ variable to ‘On’, restart your webserver and your short tags will become active again.

Tags: ,
This entry was posted on Monday, September 20th, 2010 at 7:00 pm by +Steve Marks and is filed under PHP, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first