summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortubalmartin <tubalmartin@gmail.com>2012-03-04 16:01:11 +0100
committertubalmartin <tubalmartin@gmail.com>2012-03-04 16:01:11 +0100
commit1a6971030718e2e92e6fc80750f7a14faf035257 (patch)
treed8fa7cc6354aed4b97d4582253c90dc1d85b1086
parent3edd88eee84886fc6ba3e1fc25beda3c424370bc (diff)
Allow developers to use any string as a separator, not just dashes or underscores.
Backwards compatible when using 'dash' or 'underscore' as string separator. Tests: http://codepad.org/DWcxVH5r
-rw-r--r--system/helpers/url_helper.php29
1 files changed, 19 insertions, 10 deletions
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index cdb6dae9c..f1e8c6ac6 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -466,25 +466,34 @@ 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)
{
- $replace = $separator == 'dash' ? '-' : '_';
+ if ($separator == 'dash')
+ {
+ $separator = '-';
+ }
+ else if ($separator == 'underscore')
+ {
+ $separator = '_';
+ }
+
+ $q_separator = preg_quote($separator);
$trans = array(
- '&.+?;' => '',
- '[^a-z0-9 _-]' => '',
- '\s+' => $replace,
- $replace.'+' => $replace
+ '&.+?;' => '',
+ '[^a-z0-9 _-]' => '',
+ '\s+' => $separator,
+ '('.$q_separator.')+' => $separator
);
$str = strip_tags($str);
@@ -499,7 +508,7 @@ if ( ! function_exists('url_title'))
$str = strtolower($str);
}
- return trim($str, $replace);
+ return trim($str, $separator);
}
}