MySQL function (and query) to convert a string into a slug for readable URL permalinks

MySQL Master-Master Replication setup in 5 easy steps

Today I had to fix a nasty issue in one of my PHP-based websites: to put it into few words, I needed to find a way to trasform a number of post titles into slugs, meaning that I had to remove accents, diacritics, special characters and so on and have them replaced with URL-valid characters such as hypens and underscore.

Here’s the function I came up with:

That’s basically it.

Once created, it can be used in the following way:

It should return the following valid slug:

This function was more than enough to save my day: if you stumbled upon this post, I sincerely hope that it will be the same for you!

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it's also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies. Microsoft MVP for Development Technologies since 2018.

View all posts by Ryan

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.