Make a string's first character as uppercase - PHP

To make a string’s first character as uppercase, we can use a PHP function called ucfirst.

string ucfirst ( string $string )

Returns a string with the first character of $string capitalized, if that character is alphabetic.

Example

$foo = 'hello world!';
$foo = ucfirst($foo);             // Hello world!

$bar = 'HELLO WORLD!';
$bar = ucfirst($bar);             // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!

Need Help?

Do you need any help on PHP? I'm happy to help you.

Contact Me

Recent Posts

  1. Move files recursively from source to remote server - SCP Command
  2. Brief about Magento 2 cache commands
  3. Magento 2 customer account password options
  4. Enable or disable maintance mode - Magento 2
  5. Replace string in multiple files - Command line


Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch.