开发者

"Compiling" content with short tags to var, without eval()

开发者 https://www.devze.com 2022-12-29 04:12 出处:网络
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.

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 ou开发者_运维问答tput buffering does not parse the short tag code because it happens at runtime.

Using eval() is simply not an option.

Suggestions?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号