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!

6
  • 3
    Check the output of phpinfo() and see if short_open_tag is on. Commented May 2, 2012 at 15:20
  • 3
    Do you have short tags enabled in php.ini? Commented May 2, 2012 at 15:21
  • possible duplicate of How to enable PHP short tags? Commented May 2, 2012 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(). Commented May 2, 2012 at 15:34
  • @Claudiu StackOverflow search doesn't seem to work with <?=, and Google doesn't post any helpful results either. Commented May 2, 2012 at 16:12

3 Answers 3

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');

Sign up to request clarification or add additional context in comments.

3 Comments

I was just about to say the same myself! For reference, php.net/manual/en/ini.core.php#ini.short-open-tag
just mentioned that uri in my answer with an example on how to check that option in php
Thanks, this was it! Maybe you should edit the link to point to the English version though?
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. :)

2 Comments

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
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
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.