- Forums
- PHP
- Capitalize The First Letter Of Every Word In A PHP String
this page will show you how to capitalize the first letter of every word in a string using PHP and HTML code. i will give you examples to see how i am able to capitalize the words in a string with sample script code [1040], Last Updated: Sat May 18, 2024
wallpaperama
Wed Jun 20, 2007
0 Comments
1475 Visits
if you are creating website, as a webmaster, you need to know as much as you can when designing websites also.
so lets say you have a database with user's name, you have the first name and the last name, well, you want capitalize their names, just in case they are not in your databse, so once you have done a query in your database and got a name by "john".. as you can see, john is not capitalize, so to put the a capital letter or an upper case letter on the firs character of the word john, we can use php ucwords() function:
echo ucwords($string);
or how about you have a title of your page, its important to capitalize it, for example, our title of our page is:
$string = "wallpaperama is an amazing collection of wallpapers";
so to capitalize our title, we can use this code:
<?php
$string ="wallpaperama is an amazing collection of wallpapers";
echo ucwords($string);
?>
and this is how it would display or show on your browser:
Wallpaperama Is An Amazing Collection Of Wallpapersas you can see, this is a way to put capital letters on all the words in a sentence