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

2012-02-07 Thread Dotan Cohen
On Tue, Feb 7, 2012 at 19:31, Dotan Cohen  wrote:
> function is_strong($char) {
>    if (  in_array($char, $arrayOfRtlCharacters)  ) {
>        return "RTL";
>    }
>    if (  in_array($char, $arrayOfLtrCharacters)  ) {
>        return "LTR";
>    }
>    return FALSE;
> }
>

On second thought, you might want to try preg_match() instead of
in_array() to use character ranges.


-- 
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



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

2012-02-07 Thread Dotan Cohen
On Tue, Feb 7, 2012 at 10:37, Michelle Konzack
 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
>
>    
>      $SOME_TEXT
>    
>
> 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



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

2012-02-07 Thread Ashley Sheridan
On Tue, 2012-02-07 at 09:37 +0100, Michelle Konzack 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
> 
> 
>   $SOME_TEXT
> 
> 
> 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
> 


If I understand you correctly, you want to detect the language of a
string, or is it a substring within a string?

I'm not sure how easy that would be, given that some shorter sentences
might be common across languages, but I would hazard a guess that they
would also share the direction, so that shouldn't be a major issue.

I don't know of any way to do that, but could you possibly look for
certain characters in the string that would hint at the language? It
wouldn't work too well with mixed-language strings, but it might be
enough for what you want here?

-- 
Thanks,
Ash
http://www.ashleysheridan.co.uk