Saturday, September 14, 2013

[PHP] make first character of the sentence to uppercase.

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

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

Reference: http://php.net/manual/en/function.ucfirst.php

No comments :

Post a Comment