PHP Snippets
Convert String To Title Case

This function converts a string to title case. It first converts the entire string to lowercase using strtolower, then uses ucwords to capitalize the first letter of each word. This is useful for formatting text to make it more readable or aesthetically pleasing.
PHP Function:
function toTitleCase($str) { return ucwords(strtolower($str)); }
// Example
echo toTitleCase('hello, world!'); // 'Hello, World!'
echo toTitleCase('PHP IS GREAT'); // 'Php Is Great'
Back to Home
Share:
Comments
Share your thoughts and join the conversation
No comments yet
Be the first to share your thoughts!
Failed to load comments
Please try refreshing the page
Leave a Comment