Created
February 18, 2018 17:40
-
-
Save lenivene/1cab32212acac9de695aad5c35cace32 to your computer and use it in GitHub Desktop.
Get initial letters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function initial_letters( $char ){ | |
// Defaults | |
$pos = 0; | |
$saida = ''; | |
if( !isset( $char ) ){ | |
trigger_error( "Insert text", E_USER_ERROR ); | |
return false; | |
} | |
while( ( $pos = mb_strpos( $char, ' ', $pos ) ) !== false ){ | |
if( isset( $char[$pos + 1] ) && $char[ $pos + 1 ] != ' ' ){ | |
$saida .= mb_substr( $char, $pos + 1, 1 ); | |
} | |
$pos++; | |
} | |
return $char[0] . $saida; | |
} | |
// Example: | |
$char = "Lenivene Bezerra"; | |
print initial_letters( $char ); // Return LB |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment