0

I'm migrating an existing PHP app over from an Apache 2 to nginx server and I've run into a problem: nginx will execute php fine when it is embedded within <?php ?> tags, but not when it's just <? ?> tags. In the interest of migrating this application without rewriting the code, how can I accomadate this less conventional php escape character?

aksu
  • 5,221
  • 5
  • 24
  • 39
rgb
  • 3,144
  • 3
  • 17
  • 26
  • 1
    http://www.php.net/manual/en/ini.core.php#ini.short-open-tag It's nothing to do with nginx. it's purely a PHP configuration thing. – Marc B Jan 23 '14 at 16:45
  • 1
    possible duplicate of [How to enable PHP short tags?](http://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags) – Daniel Rucci Jan 23 '14 at 16:47
  • Don't use short tags simple. Open every .php file in notepad++ (or other editor) use find and replace all occurances of " " with " – Dave Jan 23 '14 at 16:49
  • @Dave There are many situations where this would be a bad idea. What if it is 100 pages. Or what if he has ` $var = '?> now what? '; ?>`. In my answer there is a link to some really good info on how to do this. – DutGRIFF Jan 23 '14 at 17:05
  • @DutGRIFF in your examples the first one would replace just fine although its syntatically incorrect, and your second example would also throw a syntax error you'd never see either in real code. also 100pages + is nothing my current project is upwards of 1000 pages and notepad++ quite happily opens them all at once and does a find and replace – Dave Jan 23 '14 at 17:29
  • @Dave I don't think you would have a problem with that many files if you do it right in notepad++ but how does putting `` in a string give you an error. Would this not run in php ` echo " "; ?>`? I don't ever use php but I figured this would output `` just fine. – DutGRIFF Jan 23 '14 at 18:51
  • notepad++'s find and replace accepts regex's so you can tell it to ignore anything between " or ' – Dave Jan 23 '14 at 20:20

2 Answers2

3

Change your php configuration file to accept short tags. Reference

php-dev
  • 6,998
  • 4
  • 24
  • 38
2

Please stop using short PHP short tags. It is 3 letters that can save huge pains in the future. This is the wrong way of doing it. PHP.net confirms this here. Just change all of your <? to <?php. Please view this question to see how you can easily change all of your <? to <?php for the entire project. Or if you want a simple shell script you may check out henriquemoody's remove-php-short-tags.sh. It looks like it could be pretty helpful.

If you want more reasons to change from php short tags to the right way just google "Why php short tags are bad" and you will see. Jetpack 2.0.1 is a good example.

Community
  • 1
  • 1
DutGRIFF
  • 5,103
  • 1
  • 33
  • 42
  • Yes! It strongly recommended to use the standard tag form (neither **short tags** nor **asp tags**) – php-dev Jan 23 '14 at 16:52