Sunday, December 21, 2025
HomeLanguagesHow to convert first character of all the words uppercase using PHP...

How to convert first character of all the words uppercase using PHP ?

To convert the first character of all the words present in a string to uppercase, we just need to use one PHP function i.e. ucwords().

ucwords(string,delimiters): This function takes 2 parameters. The first one is the string which is mandatory. The second parameter is the delimiter. 

Example 1:

PHP




<?php
  echo ucwords("welcome to neveropen for neveropen");
?>


Output

Welcome To Geeks For Geeks

 The second parameter(delimiter) is optional. If we don’t mention it, then it will capitalize all the words after space. The echo keyword is used to print the output on the screen.

Example 2:

PHP




<?php
    // code
  echo ucwords("hey!let's get started","!")
?>


Output

Hey!Let's get started

As “!” is the delimiter, it will only capitalize the first letter of the word before and after “!”.

Example 3:

PHP




<?php
    // code
  $str = 'php is fun learning';
  $str = ucwords($str);
  echo $str
?>


Output

Php Is Fun Learning

For storing a string in a variable we need to put $ sign in front of the variable.

RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
111 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12038 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6911 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS