[eluser]sophistry[/eluser]
i went looking for site_url() comments in the bug reports forum but found none.
here's the bug... site_url() is sloppy and needs to be trim.
check this bug report:
http://codeigniter.com/bug_tracker/bug/s...g_replace/
then run this code and tell me you aren't convinced that a little change is necessary:
Code:
function test_trim($str='')
{
$tot = 10000;
$uri = '/string/';
$uri = str_repeat($uri,4);
// start with trim (the winner)
$i = 1;
$time_start = $this->microtime_float();
while ($i <= $tot)
{
$ret = trim($uri,'/');
$i++;
}
$time_end = $this->microtime_float();
$time = $time_end - $time_start;
$this->pre($ret);
$this->pre($time);
// original regex with double quotes. yuck.
// send this a long uri and it slows down
$i = 1;
$time_start = $this->microtime_float();
while ($i <= $tot)
{
$ret = preg_replace("|^/*(.+?)/*$|", "\\1", $uri);
$i++;
}
$time_end = $this->microtime_float();
$time = $time_end - $time_start;
$this->pre($ret);
$this->pre($time);
// same regex, single quotes!
$i = 1;
$time_start = $this->microtime_float();
while ($i <= $tot)
{
$ret = preg_replace('|^/*(.+?)/*$|', '\\1', $uri);
$i++;
}
$time_end = $this->microtime_float();
$time = $time_end - $time_start;
$this->pre($ret);
$this->pre($time);
}
function microtime_float()
{
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
// function to print with pre
function pre($x){echo '<pre>';print_r($x);echo '</pre>';}