views:

107

answers:

2

Nah, looks like it was hosting fault.

Who can make this code shorter?

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;
    }
+1  A: 

Have you tried Smarty? It already does what you need and more.

Tom
Yup, I've tried. However I really like to build things on my own (at least 90% ;D). Maybe best solution will be return to smarty.
Misiur
If something is already built for you, why waste your time re-inventing the wheel when you could be getting on with solving a real problem?
Johnsyweb
In the case of Smarty, it actually does what you want it to do. It already does that 90% and you can always change the 10% with custom plugins.
Tom
A: 

If your in the market for a templating engine, Twig, a new templating engine used by symfony, is much better than smarty IMHO. If your interested in doing more than just simple HTML + foreach loop (it can do that too), Twig has features such as template inheritance, macros, and low performance overhead.

Kendall Hopkins