Created
July 30, 2020 21:58
-
-
Save martsie/9e4b5a79fdfc5c528829c09538a06968 to your computer and use it in GitHub Desktop.
Split a name into first name and last initial without UTF8 malformed errors
This file contains 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 convertName($full_name) { | |
$split_name = explode(' ', $full_name); | |
if (count($full_name) !== 2) { | |
// Single word name. | |
return $full_name; | |
} | |
// Must use mb_substr otherewise utf8 issues can occur with foreign names. | |
return mb_substr($split_name[0], 0, 1) . ' ' . mb_substr($split_name[1], 0, 1) . '.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment