[eluser]MikeHibbert[/eluser]
[quote author="dbashyal" date="1237829071"][quote author="Johan André" date="1237311450"]Nice!
But what's wrong with the url_title() from the url-helper included in CI?[/quote]
haha i had no idea too that it existed so i end up making this function to achieve that result for my CMS codefight.:
Code:
/*
* Create and return clean url segment
*/
function link_clean($segment = false)
{
/*
* START: Clean Segment
*/
$segment = preg_replace('|[^a-z0-9]+|i','-',strtolower($segment));
//remove last dashes if any
while(substr($segment, -1) == '-') {
$segment = substr($segment, 0, -1);
}
//remove first dashes if any
while(substr($segment, 0, 1) == '-') {
$segment = substr($segment, 1);
}
/*END: Clean Segment*/
return $segment;
}
But the question is which is faster

[/quote]
Is there a point when this might become realtime critical?
As is it seems right that you made your own as we establish above, the built in function doesnt strip out invalid characters.
I hazard a guess that mine is faster than yours as I dont have any while loops in mine. Worth testing though if you have time
Mike