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

From: Date: Tue, 07 Feb 2012 17:31:22 +0000
Subject: Re: How to detect languages from (=> LTR vs RTL)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-316530@lists.php.net to get a copy of this message
On Tue, Feb 7, 2012 at 10:37, Michelle Konzack <linux4michelle@tamay-dogan.net> 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

« previous php.general (#316530) next »