Re: Custom Open Tags

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

 



Sven Schwyn wrote:
> 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 :-)

I don't think you can do that in any efficient way with just tweaking PHP
settings, or even PHP source...

What you *COULD* do is write a PHP script to read your PHP script and
http://php.net/eval the stuff inside of <?mytag tags, and leave the rest
alone for the real PHP server to handle...

<?php
//Untested code:
  $file = implode('', file("$php_source"));
  $parts = explode('<?mytag', $file);
  $result = $part[0];
  unset($parts[0]);
  while (list(, $part) = each($parts)){
    $phphtml = explode('mytag?>', $part);
    $php = $phphtml[0];
    $html = @$phphtml[1]; //File may end with mytag?> so squash error
    $result .= eval($php);
    $result .= $html;
  }
  //Dump $result into some file somewhere...
?>

Sounds like you inventing yet another Template language, though, to tell
you the truth, and there's already too many of them. :-)

I happen to think PHP all by itself is more than sufficient, and if
Graphic Designers can't cope with ignore the PHP tags, just hire different
Graphic Designers. :-)

You may want to look at Smarty and phplip (?) and some of the dozens of
other PHP-based template solutions.  Just cuz I hate them doesn't mean you
will. :-P

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
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