By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

Convert String to Lowercase With PHP

How to convert uppercase letters to lowercase using PHP.

Edited: 2014-12-28 03:54

Sometimes you want to convert uppercase strings to lowercase, perhaps to create a good URL for your articles – this PHP tutorial shows how to convert uppercase letters to lowercase.

We will be using the strtolower PHP function in this tutorial. The strtolower function only has a single parameter that we care about, this is the string parameter, which takes the string that we want to convert to lowercase.

The below PHP script shows how to perform simple uppercase to lowercase conversion with the strtolower function.


Shaping your URLs with lowercase letters

Its generally agreed that lowercase letters are best for URLs, so one place where you can use this function, is when shaping your URLs. The CMS system that you are using will often shape the URL as it pleases to, but the best URL format is chosen by the author of the article.

URLs should consist of lowercase letters and dashes, so a good URL would look similar to the below:

/Tutorials/uppercase-to-lowercase

You should not include a trailing slash, unless the page in question is a index type of page.

See also:Trailing slashes in URLs

The PHP strtolower function can also be used on strings that contain dashes, an example can be seen below.


The same page should not be accessible on two different URLs, and uppercase urls are considered different than lowercase – it is therefor best to just choose one format, and stick with it.