Jump to content

How do I make stuff like <!-- IF --> or <!-- ENDIF -->


Ruko

Recommended Posts

  Quote

example:

 

<?php
$file = '/my/templates/template1.tmpl';
$handle = fopen($file, 'rb');
$str = fread($handle, filesize($file));
fclose($handle);


$str = preg_replace("~<!-- ECHO:(.+?) -->~si", "$1", $str);
echo $str;
?>

 

How about stuff like <!-- IF LOGGED IN --> or <!-- INCLUDE -->

<?php
$file = '/my/templates/template1.tmpl';
$handle = fopen($file, 'rb');
$str = fread($handle, filesize($file));
fclose($handle);


if(preg_match("~<!-- IF LOGGED IN -->~si", $str)){
    // user is logged in
}

if(preg_match("~<!-- INCLUDE:(.+?) -->~si", $str, $matches)){
    include $matches[1];
}
?>

 

I didn't test...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.