views:

46

answers:

1

To start off, let me clear the air by saying we are aware of the dis/advantages to using short tag syntax in PHP. That is not what this question is about.

Is there a way to "include" a file containing short tag code, into a variable, and have PHP actually parse the code?

include/require obviously do not provide the data in a workable form, and output buffering does not parse the short tag code because it happens at runtime.

Using eval() is simply not an option.

Suggestions?

+1  A: 
ob_start();
$ini_sot = ini_get('short_open_tag');
ini_set('short_open_tag', 1);
include('file_with_short_tags.php');
ini_set('short_open_tag', $ini_sot);
$variable = ob_get_contents();
ob_end_clean();

I'm not sure what you meant in your question about how output buffering was not suitable, but I have used it anyway. I'm assuming your issue is that short_open_tags is not enabled on your platform, and maybe you just have to enable it temporarily in your code.

Martin
note that `ini_set` will return the old value (if it can)
salathe
That's a great answer but I think PHP just changed the ability to change short_tags on the fly like that, see http://us2.php.net/manual/en/ini.core.php#ini.short-open-tag. In >4<5.3 it worked but >=5.3 it has to be php.ini, .htaccess or httpd.conf, etc. (http://us2.php.net/manual/en/configuration.changes.modes.php)
Hans
You are exactly right. Before I got far enough to check, another source told me it was most definitely a difference between compile time vs runtime. Thank you!
Spot