Fetching Initials of the Commentator in the WordPress Website

Here is function that return you the comment author initials by the comment id

function get_comment_author_initials($comment_id) {
    $author = get_comment_author($comment_id);
    $words = explode(" ", $author);
    $initials = null;
    foreach ($words as $w) {
        $split = mb_str_split($w); // to cover unicode char
        $initials .= $split[0];
    }
    return $initials;
}

function mb_str_split( $string ) {
    return preg_split('/(?<!^)(?!$)/u', $string );
}

And you can use it in your code like this

<div class="class2">
    <?php echo get_comment_author_initials($comment->comment_ID); ?>
</div>