In this post we will be creating a PHP script that will change the case of an existing string. To do this we will be using the following functions.
- strtolower() – This function makes a string lowercase.
- strtoupper() – This function makes a string uppercase.
See the below snippet of code which will change the case of our string to all lowercase. This would return ‘she sells seashells by the seashore’ as output
<?php $str = "She Sells Seashells By The Seashore"; $str = strtolower($str); echo $str; ?>
See the snippet of code below which changes the case of our string to all uppercase. This would return ‘SHE SELLS SEASHELLS BY THE SEASHORE’ as output
<?php $str = "She Sells Seashells By The Seashore"; $str = strtoupper($str); echo $str; ?>