How to uppercase the first character of each word in a string with PHP

5 Answers

0 votes
$s = 'han solo';
$s = ucwords($s);  
echo $s;
 

/*
run: 

Han Solo 

*/

 



answered Jul 22, 2016 by avibootz
0 votes
$s = 'Darth Vader';
$s = ucwords($s);  
echo $s;
 

/*
run: 

Darth Vader  

*/

 



answered Jul 22, 2016 by avibootz
0 votes
$s = 'HELLO WORLD';
$s = ucwords($s);  
echo $s;
 

/*
run: 

HELLO WORLD 

*/

 



answered Jul 22, 2016 by avibootz
0 votes
$s = 'jabba|the|hutt';
$s = ucwords($s);  
echo $s;
 

/*
run: 

Jabba|the|hutt 

*/

 



answered Jul 22, 2016 by avibootz
0 votes
$s = 'JABBA THE HUTT';
$s = ucwords(strtolower($s)); 
echo $s;
 

/*
run: 

Jabba The Hutt 

*/

 



answered Jul 22, 2016 by avibootz
...