wiredesignz - 21 April 2008 10:55 AM
Yep, Seems Ok. But why not use foreach instead of count() & for?
OK. As you wish.
if (preg_match_all('/\{(\w*)\}/siU', $template, $matches))
{
foreach ($matches[0] as $key => $match)
{
if (($line = $this->lang->line("$matches[1][$key]")) === FALSE) $line = $matches[1][$key];
$template = str_replace($match, $line, $template);
}
}
wiredesignz - 21 April 2008 10:55 AM
Also are you sure preg_match_all, doesn’t just use a repeated preg_match?
Pretty sure. I tested it. For a small pack of vars (around 5) preg_match is faster, but preg_match_all wins at higher amounts of vars.
wiredesignz - 21 April 2008 10:55 AM
Maybe preg_replace_callback would be faster again?
Maybe. But then you need to write a function only to pass as parameter to preg_replace_callback or use create_function that makes the code hard to read.
Well, I am not a “performance Zealot”, but regular expressions are very slow and if calling functions inside loops is bad, calling regular expressions inside loops must be very bad.