Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP range for hebrew alphabets

Tags:

php

range

PHP has a function range('a','z') which prints the English alphabet a, b, c, d, etc. Is there a similar function for hebrew alphabets?

like image 675
user1199227 Avatar asked Feb 09 '12 09:02

user1199227


1 Answers

You can do something like this:

function utfOrd($c) {       
    return intval(array_pop(unpack('H*', $c)),16);      
}

function utfChr($c) {
return pack('H*', base_convert("$c", 10, 16));
}

var_dump(array_map('utfChr', range(utfOrd('א'), utfOrd('ת'))));

Prints:

array
  0 => string 'א' (length=2)
  1 => string 'ב' (length=2)
  2 => string 'ג' (length=2)
  3 => string 'ד' (length=2)
  4 => string 'ה' (length=2)
  5 => string 'ו' (length=2)
  6 => string 'ז' (length=2)
  7 => string 'ח' (length=2)
  8 => string 'ט' (length=2)
  9 => string 'י' (length=2)
  10 => string 'ך' (length=2)
  11 => string 'כ' (length=2)
  12 => string 'ל' (length=2)
  13 => string 'ם' (length=2)
  14 => string 'מ' (length=2)
  15 => string 'ן' (length=2)
  16 => string 'נ' (length=2)
  17 => string 'ס' (length=2)
  18 => string 'ע' (length=2)
  19 => string 'ף' (length=2)
  20 => string 'פ' (length=2)
  21 => string 'ץ' (length=2)
  22 => string 'צ' (length=2)
  23 => string 'ק' (length=2)
  24 => string 'ר' (length=2)
  25 => string 'ש' (length=2)
  26 => string 'ת' (length=2)

If you need some more characters, you can use this to create your hardcoded array or merge few ranges.

like image 50
Nayjest Avatar answered Nov 15 '22 12:11

Nayjest