-1

不,看起来它是托管错误。

谁能让这段代码更短?

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;
    }
4

2 回答 2

1

你试过Smarty吗?它已经可以满足您的需要以及更多功能。

于 2010-05-23T17:34:09.603 回答
0

如果您在市场上购买模板引擎,symfony使用的新模板引擎Twig比 smarty 恕我直言要好得多。如果您感兴趣的不仅仅是简单的 HTML + foreach 循环(它也可以这样做),Twig 具有模板继承、宏和低性能开销等功能。

于 2010-05-24T02:57:45.207 回答