I'm using the following code to display only the last name first character on my Wordpress site:
$name = $comment->comment_author;
$separate = mb_split(" ", $name);
$last = array_pop($separate);
echo implode(' ', $separate)." ".$last[0].".";
It works great with English names, but $last[0]
will return a question mark when used with a foreign language (e.g Arabic, Hebrew, Greek etc). For example:
Name: השם שלי
Will return:
השם ?.
I've been trying to fix this for an hour now, but nothing so far.
Any idea?