Shortening code

Posted by Misiur on Stack Overflow See other posts from Stack Overflow or by Misiur
Published on 2010-05-23T17:14:36Z Indexed on 2010/05/23 17:40 UTC
Read the original article Hit count: 327

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about regex