Re: Custom Open Tags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all

Thanks for your hints. I need this feature for an easy to use minimalistic CMS solution, so tweaking the PHP source is not that much of an option. But evals do the trick of course. I ruled that out at first because I thought it'll cause a lot of clumsy code. Yet there's quite an elegant way to do it, I mail it for future reference:

/**
* Includes a file executing <?mc ... ?> tags as if they were <?php ... ?> tags.
*
* @param string $file file to include
* @param bool $php whether to execute <?php ... ?> tags as well
*/
function xinclude($file, $php=TRUE) {
$content = file_get_contents($file);
if (!$php) { $content = preg_replace('/<\?php.*?\?>/', '', $content); }
$content = str_replace("<\x3Fmc", "<\x3Fphp", $content);
$content = "print '".str_replace(array("<\x3Fphp", "\x3F>"), array("'; ", "; print '"), $content)."';";
eval($content);
}


The only downside: No single quote (') is possible outside <?xyz ... ?> tags in the file included. This can of course be fixed, but only with a ridiculous amount of code. If only there was a way to do heredoc strings that DON'T parse variables (like in Perl).

-sven

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux