My previous related question:
php work with images : write complete word in arabic , ttf font
My problem was:
- If I want to write
احمد
in image it appears asد م ح ا
- Well, I fixed it and now the output:
ا ح م د
Using this function:
function arab($word){
$w = explode(' ',$word) ;
$f = array(array('ا','أ'),'ب','ت','ث','ج','ح','د','ذ','ر','ز','س','ش','ص','ض','ط','ظ','ع','غ','ف','ق','ك','ل','م','ن','ه','و','ى');
$t = array(array('ا_','أ_'),'ب_','ت_','ث_','ج_','ح_','د_','ذ_','ر_','ز_','س_','ش_','ص_','ض_','ط_','ظ_','ع_','غ_','ف_','ق_','ك_','ل_','م_','ن_','ه_','و_','ى_');
$my_arab = '' ;
foreach($w as $wo)
{
$r = array() ;
$wo = str_replace($f , $t ,$wo);
$ne = explode('_', $wo) ;
foreach($ne as $new) {
$new = str_replace('_','',$new) ;
array_unshift($r , $new);
}
$my_arab .= ' '.implode('',$r) ;
}
return trim($my_arab) ;
}
But the new problem is:
ا ح م د
(separated letters) where it should be:
احمد
How can I fix this?
Your way of reversing Arabic characters does not take into account the nature of connected glyphs. However, it is a valid trick to solve the issue of PHP/GD not automatically supporting RTL languages like Arabic.
What you need to do is to use ar-php library that does exactly what you intended.
Make sure your PHP file encoding is in unicode/UTF.
e.g. > open Notepad > Save As > encoding as UTF-8:
Sample usage for Arabic typography in PHP using imagettftext:
Outputs:
I Used this whitout any problem: https://github.com/omid/Persian-Log2Vis
UPDATE: i forked Persian-Log2Vis and change some codes to work fine. https://github.com/tahmasebi/Persian-Log2Vis
you must use bidi converter i use it to write persian in images