带有下划线字符的Concat希伯来语字符

I am trying to build a function that converts a string to an underlined one. It works on english string but not on hebrew string.

This is the function:

function underline($str){
    $tmp_word = '';
    foreach(str_split($str) as $char){
        $tmp_word.= $char.'̲';
    }
    return $tmp_word; 
}

And some cases:

echo underline('abcd') . "<br>";
$hebrew_word = 'אבגד';
echo underline($hebrew_word) . "<br>";
echo underline( hebrev(iconv("UTF-8", "ISO-8859-8", $hebrew_word))). "<br>";
echo underline(iconv("ISO-8859-8", "UTF-8", hebrev(iconv("UTF-8", "ISO-8859-8", $hebrew_word)))). "<br>";

The output is:

a̲b̲c̲d̲
�̲�̲�̲�̲�̲�̲�̲�̲
�̲�̲�̲�̲
�̲�̲�̲�̲�̲�̲�̲�̲

Is there a solution?

This has nothing to do with Hebrew, and everything to do with str_split not being multibyte-safe.

Try using this function:

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

This will return an array of characters, as opposed to an array of bytes. The rest of your code should work fine on this.