Tuesday 17 July 2018

Opening PHP Tags Not Being Recognised

Opening PHP Tags Not Being Recognised

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:

  1. ; This directive determines whether or not PHP will recognize code between  
  2. <? and ?> tags as PHP source which should be processed as such. It's been  
  3. ; recommended for several years that you not use the short tag "short cut" and  
  4. ; instead to use the full <?php and ?> tag combination. With the wide spread use  
  5. ; of XML and use of these tags by other languages, the server can become easily  
  6. ; confused and end up parsing the wrong code in the wrong context. But because  
  7. ; this short cut has been a feature for such a long time, it's currently still  
  8. ; supported for backwards compatibility, but we recommend you don't use them.  
  9. ; Default Value: On  
  10. ; Development Value: Off  
  11. ; Production Value: Off  
  12. ; http://php.net/short-open-tag  
  13. short_open_tag = Off  
Simply turn the ‘short_open_tag’ variable to ‘On’, restart your webserver and your short tags will become active again.

0 comments:

Post a Comment