system/helpers/url_helper.php - line 397
BEFORE: 10000 iterations take about 0.6535 seconds
function url_title($str, $separator = 'dash')
{
if ($separator == 'dash')
{
$search = '_';
$replace = '-';
}
else
{
$search = '-';
$replace = '_';
}
$trans = array(
$search => $replace,
"\s+" => $replace,
"[^a-z0-9".$replace."]" => '',
$replace."+" => $replace,
$replace."$" => '',
"^".$replace => ''
);
$str = strip_tags(strtolower($str));
foreach ($trans as $key => $val)
{
$str = preg_replace("#".$key."#", $val, $str);
}
return trim(stripslashes($str));
}
AFTER: 10000 iterations take about 0.3301 seconds
function url_title_geert($str, $separator = 'dash') {
// Would you like dashes or underscores, sir?
$separator = ($separator == 'dash') ? '-' : '_';
// Let's prepare our string.
$str = trim($str, " -_\t\n\r");
$str = strtolower($str);
$str = strip_tags($str);
// Time for the hard work now, just two regexes.
$str = preg_replace('/[-_\s]+/', $separator, $str);
$str = preg_replace('/[^a-z0-9'. $separator .']/', '', $str);
// All done.
return $str;
}
Twice as fast. Woot!
