How to convert title to URL slug in CodeIgniter

If you have a blog in which you’d like to use the title of your entries in the URL, you need to convert them to URL slugs. CodeIgniter’s built-in library offer a method to help us with this task.

URL Helper is a library which assists in working with URLs. You can use this helper’s methods retrieve data or format URL such as getting application’s base URL/domain and printing a link with anchor.

In this post, we will talk about url_title, which takes a string as input and creates a human-friendly URL string.

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
$title = "Convert title to URL slug in CodeIgniter";
$url_title = url_title($title, '-', true);
//output: convert-title-to-url-slug-in-codeigniter

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.