url_title()

url_title($str, $separator = '-', $lowercase = FALSE)

Parameters:
  • $str (string) – Input string
  • $separator (string) – Word separator
  • $lowercase (bool) – Whether to transform the output string to lower-case
Returns:

URL-formatted string

Return type:

string

Takes a string as input and creates a human-friendly URL string. This is useful if, for example, you have a blog in which you’d like to use the title of your entries in the URL. Example:

$title = "What's wrong with CSS?";
$url_title = url_title($title);
// Produces: Whats-wrong-with-CSS

The second parameter determines the word delimiter. By default dashes are used. Preferred options are: - (dash) or _ (underscore)

Example:

$title = "What's wrong with CSS?";
$url_title = url_title($title, 'underscore');
// Produces: Whats_wrong_with_CSS

Note

Old usage of ‘dash’ and ‘underscore’ as the second parameter is DEPRECATED.

The third parameter determines whether or not lowercase characters are forced. By default they are not. Options are boolean TRUE/FALSE.

Example:

$title = "What's wrong with CSS?";
$url_title = url_title($title, 'underscore', TRUE);
// Produces: whats_wrong_with_css
doc_CodeIgniter
2016-10-15 16:32:45
Comments
Leave a Comment

Please login to continue.