2

I've ran into this issue before but don't remember what was causing it. I have a small app that uses the shorthand notation to print variables, <?=$myvar?>, but it doesn't seem to get parsed by the webserver?

Any ideas on what might be wrong here? It's a bit weird since everything else is working ok.

Thanks!

Claudiu
  • 3,261
  • 1
  • 15
  • 27
  • 3
    Check the output of `phpinfo()` and see if `short_open_tag` is on. – SenorAmor May 02 '12 at 15:20
  • 3
    Do you have short tags enabled in php.ini? – Evan Mulawski May 02 '12 at 15:21
  • possible duplicate of [How to enable PHP short tags?](http://stackoverflow.com/questions/2185320/how-to-enable-php-short-tags) – Mike B May 02 '12 at 15:24
  • Thanks for that Mike - I couldn't find it because I didn't know I should be searching for "short tags" so sorry about that. I don't mind if it's getting closed, I'm just thinking that people that run into this issue would most likely search for "=" issues. If I knew to search for short tags, I would have probably spotted it in phpinfo(). – Claudiu May 02 '12 at 15:34
  • @Claudiu [StackOverflow search doesn't seem to work with `=`](http://stackoverflow.com/search?q=%3C%3F%3D), and [Google doesn't post any helpful results either](https://www.google.com/#sclient=psy-ab&hl=en&q=site:stackoverflow.com+%3C%3F%3D&oq=site:stackoverflow.com+%3C%3F%3D&aq=f&aqi=&aql=&gs_l=hp.3...9239.9239.1.9873.1.1.0.0.0.0.37.37.1.1.0...0.0.Rl898Zi5Fdc&pbx=1&bav=on.2,or.r_gc.r_pw.,cf.osb&fp=18a8620e2315478d&biw=1440&bih=814). – Mike B May 02 '12 at 16:12
  • I knew about Google, but thought StackOverflow will work with the special characters as well. Voted to close. – Claudiu May 03 '12 at 00:59

3 Answers3

7

its a short open tag with an echo command (=). since php 5.4 its no longer marked as short open tag and therefore works even with php.ini setting short_open_tags set to off beginning with that version. for earlier versions it depends on that option.

more information:

http://php.net/manual/en/ini.core.php#ini.short-open-tag

you can check that option e.g. using $sot = ini_get('short_open_tags');

Hajo
  • 849
  • 6
  • 21
  • 1
    I was just about to say the same myself! For reference, http://www.php.net/manual/en/ini.core.php#ini.short-open-tag – n00dle May 02 '12 at 15:21
  • just mentioned that uri in my answer with an example on how to check that option in php – Hajo May 02 '12 at 15:27
  • 1
    Thanks, this was it! Maybe you should edit the link to point to the English version though? – Claudiu May 02 '12 at 15:35
4

It may be turned off in the PHP configuration. Did you try adding this to your script?

<?php
phpinfo();
?>

Anyway, try to avoid short tags because they're good for nothing except creating a portability issue. :)

IsisCode
  • 2,490
  • 18
  • 20
  • Writing less code is always better in my opinion. And as Hajo pointed out, this is future proof, just as soon as everybody updates the PHP version :) Thanks for the advice though – Claudiu May 02 '12 at 15:37
  • well may conflict with xml files, but = should be ok. when php is used as a template engine = might be ok, for libraries and class files i would prefer php – Hajo May 02 '12 at 15:47
2

Not only check for the short_opened_tags but also be sure that AddHandler application/x-httpd-php .php is in your http.conf file. If its not there please add it and restart your apache server.

Chris Snow
  • 23,813
  • 35
  • 144
  • 309
yanju
  • 21
  • 1