summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/helpers/url_helper.php36
-rw-r--r--user_guide/changelog.html5
-rw-r--r--user_guide/helpers/url_helper.html6
3 files changed, 24 insertions, 23 deletions
diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php
index 9f4b85248..f1e8c6ac6 100644
--- a/system/helpers/url_helper.php
+++ b/system/helpers/url_helper.php
@@ -466,39 +466,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')
+ 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);
@@ -512,7 +508,7 @@ if ( ! function_exists('url_title'))
$str = strtolower($str);
}
- return trim(stripslashes($str));
+ return trim($str, $separator);
}
}
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index b87e61ba8..613c4e65d 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -71,6 +71,11 @@ Change Log
<li>Further improved MIME type detection in the <a href="libraries/file_uploading.html">File Uploading Library</a>.</li>
</ul>
</li>
+ <li>Helpers
+ <ul>
+ <li><samp>url_title()</samp> performance and output improved. You can now use any string as the word delimiter. Backwards compatible with 'dash' or 'underscore' as words delimiters.</li>
+ </ul>
+ </li>
</ul>
<h3>Bug fixes for 2.1.1</h3>
diff --git a/user_guide/helpers/url_helper.html b/user_guide/helpers/url_helper.html
index 76ec32ab2..c23c5ac92 100644
--- a/user_guide/helpers/url_helper.html
+++ b/user_guide/helpers/url_helper.html
@@ -231,11 +231,11 @@ $url_title = url_title($title);<br />
</code>
-<p>The second parameter determines the word delimiter. By default dashes are used. Options are: <dfn>dash</dfn>, or <dfn>underscore</dfn>:</p>
+<p>The second parameter determines the word delimiter. By default dashes are used.</p>
<code>$title = "What's wrong with CSS?";<br />
<br />
-$url_title = url_title($title, 'underscore');<br />
+$url_title = url_title($title, '_');<br />
<br />
// Produces: Whats_wrong_with_CSS
</code>
@@ -244,7 +244,7 @@ $url_title = url_title($title, 'underscore');<br />
<code>$title = "What's wrong with CSS?";<br />
<br />
-$url_title = url_title($title, 'underscore', TRUE);<br />
+$url_title = url_title($title, '_', TRUE);<br />
<br />
// Produces: whats_wrong_with_css
</code>