Forum Moderators: coopster
$dir = opendir("include");
while ($filename = readdir($dir)){
if ($filename!= '.' && $filename!= '..' ) {
$template = str_replace("%%".$filename."%%","<? @include(\"include/$filename\");?>",$template);
$template = str_replace("%%".strtoupper($filename)."%%","<? @include(\"include/$filename\");?>",$template);
$template = str_replace("%%".strtolower($filename)."%%","<? @include(\"include/$filename\");?>",$template);}
}
As you can see, the script would read the directory where the various includes were found and use their names along with a while loop to find the tokens and parse them properly.
For upgrade purposes, I'd like to parse the tokens through a regex instead of being limited to files found in the include directory.
Unfortunatley regex, even simple ones aren't my strong suit. I know it should be fairly simple to use a regex pattern to grab the text between the %% and the %%, assign it to a variable, then add it to an include line, but I'm having difficulties today.
Any help would be appreciated.
Thanks!
$pattern = "/%%([^%]+)%%/";