Saturday, September 14, 2013

[PHP] make first character of each word to uppercase.

What's ucwords() function for ? It is for "Returning a string with the first character of each word in str capitalized, if that character is alphabetic."
<?php
$foo = 'I ATE APPLE!';
$foo = ucwords($foo);             //I Ate Apple!
$bar = 'I ATE APPLE!!';

$bar = ucwords($bar);             // I ATE APPLE!!
$bar = ucwords(strtolower($bar)); //I Ate Apple!
?>
As the example shown, you must convert the sentence to lower character first otherwise it may not work.

No comments :

Post a Comment