为什么要在SMARTY里换?~觉得如果是输出后显示的..那肯定是固定的~~何不赋变量呢?~

解决方案 »

  1.   

    没有必要这样写,这样$src也是你要在PHP中定义吧,为什么不直接定义$src="src=\"/javascript/overlib.js\"";
      

  2.   

    <* popup_init src="$src|string_format:'%soverlib.js' overlib.js" *>
      

  3.   

    兄弟不要掉死在smarty 上面去了,很不好用,很不方便。
    发个好用的给你试试。
    <?php
    /**
    * *模版引擎.
    * @author  ****
    * @package  lib
    * @version  v1.0
    * @copyright juwangTech.
    */function template($file) 
    {
    // 找到相关模版位置.
       global $tempPath;
       echo $tempPath; $templateDir=   $tempPath."tpl/";
    $templateTmpDir= $tempPath."compiled/";
    $templateDir ? null : die("not define g_tmplate_dir");
    $tplfile = $templateDir.$file.'.htm'; 
    $objfile = $templateTmpDir.$file.'.tpl.php'; 
    if(!file_exists($tplfile)) 
    {
    die("$tplfile template is not exist!"); 
    }

    // 第一次时,创建文件.
     elseif (!file_exists($objfile))
         {
             parse_template($tplfile,$objfile);
             return $objfile;
      }

        // 更新文件.在这里. 可扩展指定时间.
    if(@filemtime($tplfile) > @filemtime($objfile)) 
    {
      parse_template($tplfile,$objfile);
    }
    return $objfile;
    }/**
     * 将模版文件写成目标文件.
     * 
     * 摘要:相关流程为清除不必要的空格.相关函数正则替换.(加载模版),循环与判断实现.
     * @package lib
     * @author  juwang
     * @param  模版文件.
     * @param  目标文件.
     * */function parse_template($tplfile,$objfile)
    {
            $view_mod = 0;   
            $nest = 5;
            if(!$fp = fopen($tplfile, 'r'))
            {
                    exit("Current template file './$tplfile' not found or have no access!");
            }
            
            $template = fread($fp, filesize($tplfile));
            fclose($fp);
    //视图模视.
            if($view_mod)
            {
                 $template = "<div style='position:relative; width:100px; height:19px; z-index:1;color:white;background:#707888' >$tplfile</div>".$template;
            }


    //关于变量的正则.
            $var_regexp = "((\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(\[[a-zA-Z0-9_\"\'\$\x7f-\xff]+\])*)";
    //关于常量的正则.
            $const_regexp = "([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)";

    //清除不必要的空格.
            $template = preg_replace("/([\n\r]+)\t+/s", "\\1", $template);

    //抽取<!--$xu---> 中的$xu
            $template = preg_replace("/\<\!\-\-\{(.+?)\}\-\-\>/s", "{\\1}", $template);
     $template = preg_replace("/\{lang\s+(.+?)\}/ies", "languagevar('\\1')", $template);
            $template = str_replace("{LF}", "<?=\"\\n\"?>", $template);        $template = preg_replace("/\{(\\\$[a-zA-Z0-9_\[\]\'\"\$\x7f-\xff]+)\}/s", "<?=\\1?>", $template);
            $template = preg_replace("/$var_regexp/es", "addquote('<?=\\1?>')", $template);
            $template = preg_replace("/\<\?\=\<\?\=$var_regexp\?\>\?\>/es", "addquote('<?=\\1?>')", $template);        $template = "<?  ?>\n\n$template";


            $template = preg_replace("/\s*\{template\s+(.+?)\}\s*/is", "\n<? include template('\\1'); ?>\n", $template);


            $template = preg_replace("/\s*\{eval\s+(.+?)\}\s*/ies", "stripvtags('\n<? \\1 ?>\n','')", $template);


            $template = preg_replace("/\s*\{elseif\s+(.+?)\}\s*/ies", "stripvtags('\n<? } elseif(\\1) { ?>\n','')", $template);


            $template = preg_replace("/\s*\{else\}\s*/is", "\n<? } else { ?>\n", $template);



            for($i = 0; $i < $nest; $i++)
            {
                    $template = preg_replace("/\s*\{loop\s+(\S+)\s+(\S+)\}\s*(.+?)\s*\{\/loop\}\s*/ies", "stripvtags('\n<? if(is_array(\\1)) { foreach(\\1 as \\2) { ?>','\n\\3\n<? } } ?>\n')", $template);
                    $template = preg_replace("/\s*\{loop\s+(\S+)\s+(\S+)\s+(\S+)\}\s*(.+?)\s*\{\/loop\}\s*/ies", "stripvtags('\n<? if(is_array(\\1)) { foreach(\\1 as \\2 => \\3) { ?>','\n\\4\n<? } } ?>\n')", $template);
                    $template = preg_replace("/\s*\{if\s+(.+?)\}\s*(.+?)\s*\{\/if\}\s*/ies", "stripvtags('\n<? if(\\1) { ?>','\n\\2\n<? } ?>\n')", $template);
            }        $template = preg_replace("/\{$const_regexp\}/s", "<?=\\1?>", $template);
            $template = preg_replace("/ \?\>[\n\r]*\<\? /s", " ", $template);        if(!@$fp = fopen($objfile, 'w'))
            {
                    exit("obj template $objfile have no write!");
            }
     flock($fp, 3);
            fwrite($fp, $template);
            fclose($fp);
    }/**
     * 添加引号
     */
    function addquote($var) {
            return str_replace("\\\"", "\"", preg_replace("/\[([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\]/s", "['\\1']", $var));
    }/**
     * *去除表达式的标题.<?=$fdsaf?> 转换为 $fdsaf
     *
     * @param 表达式 $expr
     * @param 描述语句 $statement
     */
    function stripvtags($expr, $statement) {
            $expr = str_replace("\\\"", "\"", preg_replace("/\<\?\=(\\\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\[\]\"\'\x7f-\xff]*)\?\>/s", "\\1", $expr));
            $statement = str_replace("\\\"", "\"", $statement);
            return $expr.$statement;
    }
    ?>