代码之家  ›  专栏  ›  技术社区  ›  Misiur

缩短代码

  •  -1
  • Misiur  · 技术社区  · 15 年前

    不,看起来是主持失误。

    private function replaceFunc($subject)
        {
            foreach($this->func as $t)
            {
                preg_match_all('/\{'.$t.'\([a-zA-Z,\']+\)\}/i', $subject, $res);
                for($j = 0; $j < sizeof($res[0]); $j++)
                {
                    preg_match('/\([a-zA-Z,\']+\)/i', $res[0][$j], $match);
                    if($match > 0)
                    {
                        $prep = explode(", ", substr($match[0], 1, -1));
                        $args = array();
                        for($i = 0; $i < sizeof($prep); $i++)
                        {
                            $args[] = substr($prep[$i], 1, -1);
                        }
                    }
                    else
                    {
                        $args = array();
                    }
                    $subject = preg_replace('/\{'.$t.preg_quote($match[0]).'\}/i', call_user_func_array($t, $args), $subject);
                }
            }
            return $subject;
        }
    
    2 回复  |  直到 15 年前
        1
  •  1
  •   Tom    15 年前

    你试过了吗 Smarty ? 它已经满足了你的需要。

        2
  •  0
  •   Kendall Hopkins    15 年前

    如果你想买一个模板引擎, Twig ,使用的新模板引擎 symfony ,比smarty IMHO好多了。如果您对不仅仅是简单的HTML+foreach循环感兴趣(它也可以这样做),Twig具有模板继承、宏和低性能开销等特性。

    推荐文章