Slugify


the-online-slug-generator




Go » Reset » Copy to Clipboard »

Slugs are used to construct friendly URLs (often for permalinks) that are easy to type, descriptive, and easy to remember. Typically, slugs are generated from a human-readable phrase such as the title of a news article, blog post, or encyclopedia entry. It is also common practice to make the slug all lowercase and to remove non-essential words, such as conjunctions and articles, to shorten the final URL. Long page titles may also be truncated to keep the URL a reasonable length. To make the URL easier for users to type, special characters are often removed or replaced as well. For instance, accented characters are usually replaced by letters from the English alphabet; punctuation marks are generally removed; and spaces (which have to be encoded as %20 or +) are replaced by dashes (-) or underscores (_), which are more aesthetically pleasing.

Slugs are used to construct friendly URLs (often for permalinks) that are easy to type, descriptive, and easy to remember. Typically, slugs are generated from a human-readable phrase such as the title of a news article, blog post, or encyclopedia entry. It is also common practice to make the slug all lowercase and to remove non-essential words, such as conjunctions and articles, to shorten the final URL. Long page titles may also be truncated to keep the URL a reasonable length. To make the URL easier for users to type, special characters are often removed or replaced as well. For instance, accented characters are usually replaced by letters from the English alphabet; punctuation marks are generally removed; and spaces (which have to be encoded as %20 or +) are replaced by dashes (-) or underscores (_), which are more aesthetically pleasing.

"Slugify" a string so it is ascii, has only alphanumeric and hyphen characters. Useful for URLs and filenames.

Makes slugs, changes diacritics letters to latin

URL slugs are extremely common on the internet today, particularly on website blogs. The title of the post is used as an identifier in the URL instead of an id number, this makes it possible for a person looking at the URL to know what the post is generally about. For example this post in your address bar is seen as "/posts/view/using_url_slugs_in_a_cakephp_app" instead of "/posts/view/1" which makes the URL meaningful and human readable. In this article I'm going to go through the benefits of using URL slugs and how to incorporate them into the CakePHP blog application that we have been building over the previous articles. Advantages of using URL Slugs 1. Your URLS are cleaner and more readable 2. People can see what the post is about by the title 3. Can help with Search Engine Optimisation as keywords are a part of the url The String to Slug Function In the past I've been using a fairly basic function to turn a string into a url slug and that function can be seen below, however when researching this article i came across an inbuilt CakePHP function that will do the job better.

Function to slugify strings in PHP This is a function to slugify (replace non-ASCII characters with ASCII characters) strings in PHP. It tries to replace some characters like ñ or ç to a similar ASCII character (for example, it will transform a ñ to a n).

Ads



Slug the part of an URL which identifies a page using human-readable keywords