Wednesday 24 March 2021

Php: ucfirst: Make a string's first character uppercase

Signature

ucfirst ( string $string ) : string

 

Description

Returns a string with the first character of string capitalized, if that character is alphabetic. It will not update the original string.

 

Example

$msg2 = ucfirst($msg1);

 

ucfirst_demo.php

#!/usr/bin/php

<?php

    $msg1 = "hello world";
    $msg2 = ucfirst($msg1);

    echo "msg1 : $msg1\n";
    echo "msg2 : $msg2\n";

?>

 

Output

$./ucfirst_demo.php 

msg1 : hello world
msg2 : Hello world

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment