summaryrefslogtreecommitdiffstats
path: root/system/helpers
diff options
context:
space:
mode:
authortubalmartin <tubalmartin@gmail.com>2012-03-03 22:10:34 +0100
committertubalmartin <tubalmartin@gmail.com>2012-03-03 22:10:34 +0100
commit3edd88eee84886fc6ba3e1fc25beda3c424370bc (patch)
treee6c63afba628ed878b749a5514ac78944408e153 /system/helpers
parent1887c6d4847fd9d4251b58aba599cb8ee63d2e38 (diff)
An even better url_title helper. Tests: http://codepad.org/tuJgvkyN
Changelog entry added for 2.1.1
Diffstat (limited to 'system/helpers')
-rw-r--r--system/helpers/url_helper.php27
1 files changed, 7 insertions, 20 deletions
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 9f4b85248..cdb6dae9c 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -478,27 +478,14 @@ if ( ! function_exists('url_title'))
{
function url_title($str, $separator = 'dash', $lowercase = FALSE)
{
- if ($separator == 'dash')
- {
- $search = '_';
- $replace = '-';
- }
- else
- {
- $search = '-';
- $replace = '_';
- }
+ $replace = $separator == 'dash' ? '-' : '_';
$trans = array(
- '&\#\d+?;' => '',
- '&\S+?;' => '',
- '\s+' => $replace,
- '[^a-z0-9\-\._]' => '',
- $replace.'+' => $replace,
- $replace.'$' => $replace,
- '^'.$replace => $replace,
- '\.+$' => ''
- );
+ '&.+?;' => '',
+ '[^a-z0-9 _-]' => '',
+ '\s+' => $replace,
+ $replace.'+' => $replace
+ );
$str = strip_tags($str);
@@ -512,7 +499,7 @@ if ( ! function_exists('url_title'))
$str = strtolower($str);
}
- return trim(stripslashes($str));
+ return trim($str, $replace);
}
}