View Single Post
ישן 23-09-06, 11:31   # 25
RS324
תודה על תרומתך.
 
מיני פרופיל
תאריך הצטרפות: May 2006
הודעות: 3,173

RS324 לא מחובר  

טוב אז ככה, לאחר כמה ניסיונות הגעתי למסקנה שיהיה קשה להשתמש ב PREG לכן החלטתי לבסוף להשתמש ב STR_REPLACE

זאת הפונקציה :

PHP קוד:
function str_tpl($dir,$file,$what,$with)
{
 
    
$tpl file_get_contents($dir."/".$file.".tpl");
 

    if (
is_array($what) AND is_array($with))
    {
        foreach (
$what AS $key=>$val)
        {
            
$tpl str_replace($what[$key],$with[$key],$tpl);
        }
        
    }
    else 
    {
        
$tpl str_replace($what,$with,$tpl);
    }
    
        return 
$tpl;

עכשיו דוגמאות להפעלה של הפונקציה :

PHP קוד:
$patterns = array();
$patterns[0] = '<*CSS_NUM*>';
$patterns[1] = '<*BLOCK_TITLE*>';
$patterns[2] = '<*BLOCKS*>';
$replacements = array();
$replacements[0] = 'this is css num';
$replacements[1] = 'כותרת';
$replacements[2] = 'block in here';
echo 
str_tpl('style','header',$patterns,$replacements); 
דוגמא נוספת :

PHP קוד:
echo str_tpl('style','header','<*CSS_NUM*>','mynum'); 
תהנה, עובד ב 100 %