Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2007-04-07, 09:20 AM
Junior Member
 
Join Date: Dec 2006
Posts: 10
xploita is on a distinguished road
Default which way to template?

i'm developing a simple tempalte engine.
what i've been doing is that i have a .php page with the array vars() containing pair of [ToBeReplaced][$value].
i have another .html file with tags like {ToBeReplaced}.
$contents has the templateFile.html

so,when processing the template,i have two choices.
Code:
foreach ($vars as $key->$value){
     str_replace('{'.$key.'}',$value,$contents);
}
OR the other way round
Code:
preg_match_all("/{[A-Z]+[ ][A-Z]+}/",$contents,$out,PREG_PATTERN_ORDER)
foreach ($out as $key=>$value){
    if(is_array($out[$key]) ){
        foreach ($out[$key] as $key2=>$value2){
            if(isset($vars[$out[$key][$key2]])){
                $out[$key][$key2]=$vars[$out[$key][$key2]];            
            }
        }
    }
}
so,in the first one i have to use the keys in the vars() as the search criteria.and replace them in the $contents if i find any.
and in the seconed one,i read the html file first.store the patterns found and search in the vars().if i find any match i replace it.

does the seconed one posses any security threats?
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:53 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.