Re: How to detect languages from (=> LTR vs RTL)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 7, 2012 at 10:37, Michelle Konzack
<linux4michelle@xxxxxxxxxxxxxxx> wrote:
> Hi colleges and gurus,
>
> I coding a whole "web office" and one of my problems is "LTR vs RTL".
> If I have for exanple an E-Mail I use a
>
>    <div style="direction:$DIRECTION">
>      $SOME_TEXT
>    </div>
>
> but HOW can I detect the type of $SOME_TEXT  from  within  PHP,  to  set
> $DIRECTION? (RTL or LTR) correctly?
>
> And how can I do this with mixed Text (by  line  or  entired  paragraph)
> like:
>
>   german       <- must be LTR
>   persian      <------------------- must be RTL
>   english      <- must be LTR
>   arabic       <------------------- must be RTL
>   french       <- must be LTR
>   jidisch      <------------------- must be RTL
>
> Ayn Iranian (Moxhtar?), Arabs (Jasin?) or Jews (Dotan?) here  which  can
> help me please?
>
> Thanks, Greetings and nice Day/Evening
>    Michelle Konzack
>

Hi Michelle! There is no reliable way to determine the intent of the
author, but most software detects RTL vs LTR by the first "strong"
character found in the string. Strong characters are letters, not
punctuation or numbers which are used in both LTR or RTL environments.

Untested, but you might be able to do something like this:

while (!feof($input)) {
    $char = fgetc($input);
    if ( is_strong($char) ) {
        $direction=is_strong($char);
        break;
    }
}

function is_strong($char) {
    if (  in_array($char, $arrayOfRtlCharacters)  ) {
        return "RTL";
    }
    if (  in_array($char, $arrayOfLtrCharacters)  ) {
        return "LTR";
    }
    return FALSE;
}

-- 
Dotan Cohen

http://gibberish.co.il
http://what-is-what.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux