Skip to content

Instantly share code, notes, and snippets.

@lenivene
Created February 5, 2017 10:59
Show Gist options
  • Save lenivene/eff7d98baf86f1af60b9354bfa6d7019 to your computer and use it in GitHub Desktop.
Save lenivene/eff7d98baf86f1af60b9354bfa6d7019 to your computer and use it in GitHub Desktop.
First character uppercase

Example use code

$title = "hello word";

echo mb_ucfirst( $title ); // return "Hello word";
<?php
if( ! function_exists( 'mb_ucfirst' ) ){
function mb_ucfirst( $string = '', $encoding = "UTF-8" ){
if( empty( $string ) )
return false;
$strlen = mb_strlen( $string, $encoding );
$firstChar = mb_substr( $string, 0, 1, $encoding );
$end_Char = mb_substr( $string, 1, $strlen - 1, $encoding );
return mb_strtoupper( $firstChar, $encoding ) . $end_Char;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment