arabic fonts display in reverse order in dompdf

后端 未结 2 1785
無奈伤痛
無奈伤痛 2021-01-14 14:14

I am using dompdf to convert a html page using dompdf, but it is showing arabic text in reverse order

For eg if text is

ايبنسيالرمس

then it is displ

2条回答
  •  走了就别回头了
    2021-01-14 15:04

    Only issue with @BrianS answer is that left-to-right characters in the line are displayed right-to-left. This is how I solved it (in my case the check is for Hebrew characters):

    // check if the line contains Hebrew characters from the start too
    // to avoid flipping dates etc.
    if( strtolower( $style -> direction ) == 'rtl' && preg_match( "/\p{Hebrew}/u", $text ) ):
    
        preg_match_all('/./us', $text, $ar);
    
        // reverse the whole line
        $text = join('',array_reverse($ar[0]));
    
        // flip english back to ltr
        $words = explode( ' ', $text );
        foreach( $words as $i => $word ):
            if( !preg_match( "/\p{Hebrew}/u", $word ) ):
                $words[$i] = implode( '', array_reverse( str_split( $word ) ) );
            endif;
        endforeach;
    
        $text = implode( ' ', $words );
    
    endif;
    

提交回复
热议问题