PHP strtoupper() and strtolower() string functions

Manipulating text or string data is such a common task that most all programming languages provide built-in functions for this specific purpose. PHP is no different in that regard. The language comes chock-full of different string manipulating functions. If you need string data in all capitalized or upper-cased letters, you can use strtoupper(). What about all lower-case strings? The strtolower() function takes of that. In this post, we visit some rudimentary examples and gain a feel for how these 2 functions operate.

close-up-of-purple-sneakers-and-shoe-strings
Image by Isabell Demuth from Pixabay
Self-Promotion:

If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!


Below are some example uses of strtoupper() and strtolower(). Experiment with them on your particular string data to know for sure how they behave…

Lower-case, single word

1
$first_name = 'josh';
1
2
3
echo 'strtoupper(): '.strtoupper($first_name);

echo 'strtolower(): '.strtolower($first_name);
1
2
strtoupper(): JOSH
strtolower(): josh

All upper-case, single word

1
$cap_first_name = 'JOSH';
1
2
3
echo 'strtolower(): '.strtolower($cap_first_name);

echo 'strtoupper(): '.strtoupper($cap_first_name);
1
2
strtolower(): josh
strtoupper(): JOSH

Lower-case, multiple words

1
$whole_name = 'josh otwell';
1
2
3
echo 'strtoupper(): '.strtoupper($whole_name);

echo 'strtolower(): '.strtolower($whole_name);
1
2
strtoupper(): JOSH OTWELL
strtolower(): josh otwell

Upper-case, multiple words

1
$cap_whole_name = 'JOSH OTWELL';
1
2
3
echo 'strtolower(): '.strtolower($cap_whole_name);

echo 'strtoupper(): '.strtoupper($cap_whole_name);
1
2
strtolower(): josh otwell
strtoupper(): JOSH OTWELL

First letter capitalized, single word

1
$cap_name = 'Josh';
1
2
3
echo 'strtolower(): '.strtolower($cap_name);

echo 'strtoupper(): '.strtoupper($cap_name);
1
2
strtolower(): josh
strtoupper(): JOSH

First letter of each word capitalized, multiple word

1
$cap_each_name = 'Josh Otwell';
1
2
3
echo 'strtolower(): '.strtolower($cap_each_name);

echo 'strtoupper(): '.strtoupper($cap_each_name);
1
2
strtolower(): josh otwell
strtoupper(): JOSH OTWELL

Visit any of the below PHP-related blog posts I have written if you are so inclined. Please share them with others who would benefit from the content as well.


Like what you have read? See anything incorrect? Please comment below and thank you for reading!!!

A Call To Action!

Thank you for taking the time to read this post. I truly hope you discovered something interesting and enlightening. Please share your findings here, with someone else you know who would get the same value out of it as well.

Visit the Portfolio-Projects page to see blog post/technical writing I have completed for clients.



To receive email notifications (Never Spam) from this blog (“Digital Owl’s Prose”) for the latest blog posts as they are published, please subscribe (of your own volition) by clicking the ‘Click To Subscribe!’ button in the sidebar on the homepage! (Feel free at any time to review the Digital Owl’s Prose Privacy Policy Page for any questions you may have about: email updates, opt-in, opt-out, contact forms, etc…)

Be sure and visit the “Best Of” page for a collection of my best blog posts.


Josh Otwell has a passion to study and grow as a SQL Developer and blogger. Other favorite activities find him with his nose buried in a good book, article, or the Linux command line. Among those, he shares a love of tabletop RPG games, reading fantasy novels, and spending time with his wife and two daughters.

Disclaimer: The examples presented in this post are hypothetical ideas of how to achieve similar types of results. They are not the utmost best solution(s). The majority, if not all, of the examples provided, are performed on a personal development/learning workstation-environment and should not be considered production quality or ready. Your particular goals and needs may vary. Use those practices that best benefit your needs and goals. Opinions are my own.

Hey thanks for commenting! Leave a Reply

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