Include code from PHP stream

I am wondering if it is possible to create a flow wrapper to load some code from an array into using something like the following

<?php include 'template://myarraykey/'; ?>

and make it work like a normal inclusion from a file? The reason is that I do not want to store templates in the file system, they will either exist in memcache or in the database table and defiantly do not want to use eval ().

Also I would suggest that I need to enable allow_url_include?

+3
source share
4 answers

I know this is an old question ... but I think it's worth noting that you can do something like:

$content = '
  <?php if($var=true): ?>
    print this html
  <?php endif; ?>
';

This would usually be very cumbersome to evaluate, but you can do:

include "data://text/plain;base64,".base64_encode($content);

And he will understand so quickly!

+7

Include URL-. this. HTTP-, :

<?php

/* This example assumes that www.example.com is configured to parse .php
* files and not .txt files. Also, 'Works' here means that the variables
* $foo and $bar are available within the included file. */

// Won't work; file.txt wasn't handled by www.example.com as PHP
include 'http://www.example.com/file.txt?foo=1&bar=2';

// Won't work; looks for a file named 'file.php?foo=1&bar=2' on the
// local filesystem.
include 'file.php?foo=1&bar=2';

// Works.
include 'http://www.example.com/file.php?foo=1&bar=2';

$foo = 1;
$bar = 2;
include 'file.txt';  // Works.
include 'file.php';  // Works.

?>

include "template://$thevalue";

+2

eval, , . , . , , , eval. eval, "" .

+2

include , , , .

: memcached .

+1

Source: https://habr.com/ru/post/1779205/


All Articles