Site icon Ryadel

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!

Exit mobile version