I don't know how to proceed.I want clean URL with hypen on each space and special chars too to be replaced or removed but when this needs to be happen before going to database?
So, if saved to dabased with new url with spaces how to revert back to original url for titles, therefore it will be appear with spaces. Do I need to create 2 columns - one for title which will visualised for user and other column for URL.
I'm tried with this function which works perfect:
function clean_url($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);
return $clean;
}