My Computer Tips

Home | About | Categories | All Tips & Tutorials

Convert all characters to Upper or Lower case in PHP7

ID: 191

Category: PHP7

Added: 7th of October 2020

Views: 2,088

There might be occasions when you need to ensure all characters submitted through a form field are either in upper or lower case.

One example could be a form field where you ask your users to enter their website address. Some users might accidentally enter the address in upper case. In this case we can use PHP to take the user input, and convert the text to lower case, using the strtolower() function.

Please look at the examples below

To convert all characters to upper case in PHP7 use the strtoupper() function

<?php
echo strtoupper('www.mycomputertips.co.uk');
?>


Output
WWW.MYCOMPUTERTIPS.CO.UK

To convert all characters to lower case in PHP7 use the strtolower() function
<?php
echo strtolower('WWW.MYCOMPUTERTIPS.CO.UK');
?>


Output
www.mycomputertips.co.uk