Php ucwords
From w3cyberlearnings
Contents |
PHP function ucwords
This function converts the first character of each word within a string to uppercase.
Syntax ucwords
- string: string to input.
ucwords(string)
Return
- Modified string to uppercase first character of each word.
Example 1
<?php $str="you are a smart girl"; echo ucwords($str); ?>
Output
You Are A Smart Girl
Example 2: Convert uppercase first character of each array element
<?php $arr_str=array( 'john smit', 'bob jam', 'paul lamis', 'christ lee'); $all_uppcase = array_map('ucwords',$arr_str); foreach($all_uppcase as $name) { echo $name .'<br/>'; } ?>
Output
John Smit Bob Jam Paul Lamis Christ Lee