diff options
author | Phil Sturgeon <email@philsturgeon.co.uk> | 2012-03-04 16:32:58 +0100 |
---|---|---|
committer | Phil Sturgeon <email@philsturgeon.co.uk> | 2012-03-04 16:32:58 +0100 |
commit | a2bd3637c0eeb9e0e6be48dd10167febac440774 (patch) | |
tree | c2db3b5d4419e89529eaaa36cae37fe1fa8ec459 /system/helpers | |
parent | f8f04ce990a46f1967cd58def4929c476f4595a5 (diff) | |
parent | 476af3a89058861e7d44473ac01c2206ebbbe6f1 (diff) |
Updated with 2.1-stable.
Diffstat (limited to 'system/helpers')
-rw-r--r-- | system/helpers/url_helper.php | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 2cbcd9dbf..3f0fef58e 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -470,39 +470,35 @@ if ( ! function_exists('prep_url')) * Create URL Title * * Takes a "title" string as input and creates a - * human-friendly URL string with either a dash - * or an underscore as the word separator. + * human-friendly URL string with a "separator" string + * as the word separator. * * @access public * @param string the string - * @param string the separator: dash, or underscore + * @param string the separator * @return string */ if ( ! function_exists('url_title')) { - function url_title($str, $separator = 'dash', $lowercase = FALSE) + function url_title($str, $separator = '-', $lowercase = FALSE) { if ($separator === 'dash') { - $search = '_'; - $replace = '-'; + $separator = '-'; } - else + else if ($separator == 'underscore') { - $search = '-'; - $replace = '_'; + $separator = '_'; } + + $q_separator = preg_quote($separator); $trans = array( - '&\#\d+?;' => '', - '&\S+?;' => '', - '\s+' => $replace, - '[^a-z0-9\-\._]' => '', - $replace.'+' => $replace, - $replace.'$' => $replace, - '^'.$replace => $replace, - '\.+$' => '' - ); + '&.+?;' => '', + '[^a-z0-9 _-]' => '', + '\s+' => $separator, + '('.$q_separator.')+' => $separator + ); $str = strip_tags($str); foreach ($trans as $key => $val) @@ -515,7 +511,7 @@ if ( ! function_exists('url_title')) $str = strtolower($str); } - return trim(trim(stripslashes($str)), $replace); + return trim(trim($str, $separator)); } } |