[PHP] Re: Custom Open Tags
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
[PHP] Custom Open Tags
Hi folks Does anybody know whether there's a way to tell PHP to accept an alternative open tag like for instance ?mytag or ?mc along with the normal ?php tag? I'm looking for a way to have two kinds of PHP code in a page. The first kind tagged ?mc ... ? contains the PHP code to manage page elements (like includes, menus etc) while the second kind tagged ?php ... ? contains normal PHP code for dynamic pages (like DB stuff). A page resides on the Staging (Virtual) Host and contains both kind of tags. When viewing the page on the Staging Host, both open tags are executed. Yet when publishing a page to the Production (Virtual) Host, the mc-tags are executed (and thus complete the page design) while the php-tags are left untouched (as they contain the dynamic stuff). Sounds more complicated than it is :-) Thanks for your hints,-sven -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Custom Open Tags
Hi Trevor I'm not sure, but that may allow you to use ?php ? AND % % tags at the same time. Thought about that, it would actually be very elegant if it was the other way round. ASP tags would be great instead of a ?mc ... ? custom tag, however, that won't do the trick as the execution of the ?php ... ? tags can't be switched off (or can it?) when using % ... % tags. Thanks for your thoughts though! -sven -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php