PHP String function with non-English languages

I tried to use the range();function with non-English language. This does not work.

$i =0
foreach(range('क', 'म') as $ab) {

    ++$i;

    $alphabets[$ab] = $i;

}

Output : à = 1

These were the Hindi (India) alphabets. It is executed only once (output is displayed).

For this, I do not understand what to do!

So, if possible, please tell me what to do and what to do first, before thinking about working with non-English text with any PHP functions.

+5
source share
3 answers

Short answer: impossible to use range.

Description

'क' 'म' . , à.

à, () UTF-8. , à - U+00E0, 0xE0 UTF-8 'क' ( 0xE0 0xA4 0x95). , PHP , , , "start".

à, UTF-8 'म' 0xE0 ( PHP , " " 0xE0 à).

range for , , UTF-8 ( , ). , googled :

// Returns the UTF-8 character with code point $intval
function unichr($intval) {
    return mb_convert_encoding(pack('n', $intval), 'UTF-8', 'UTF-16BE');
}

// Returns the code point for a UTF-8 character
function uniord($u) {
    $k = mb_convert_encoding($u, 'UCS-2LE', 'UTF-8');
    $k1 = ord(substr($k, 0, 1));
    $k2 = ord(substr($k, 1, 1));
    return $k2 * 256 + $k1;
}

:

for($char = uniord('क'); $char <= uniord('म'); ++$char) {
    $alphabet[] = unichr($char);
}

print_r($alphabet);

.

+10

html_entity_decode() range() , (, ASCII, ):

foreach (range(0x0915, 0x092E) as $char) {

    $char = html_entity_decode("&#$char;", ENT_COMPAT, "UTF-8");
    $alphabets[$char] = ++$i;
}
+5

, .

$first = file_get_contents("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=|en&q=क");
$second = file_get_contents("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&langpair=|en&q=म"); //not real value
$jsonfirst = json_decode($first);
$jsonsecond = json_decode($second);
$f = $jsonfirst->responseData->translatedText;
$l = $jsonsecond->responseData->translatedText;
foreach(range($f, $l) as $ab) {


    echo $ab; 

}

ABCDEFGHI

, arraymap , .

0

All Articles