3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* * By Darien Hager, Jan 2007... Use however you wish, but please * please give credit in source comments. * * Change "UTF-8" to whichever encoding you are expecting to use. */ function ords_to_unistr($ords, $encoding = 'UTF-8') { // Turns an array of ordinal values into a string of unicode characters $str = ''; for ($i = 0; $i < count($ords); $i++) { // Pack this number into a 4-byte string // (Or multiple one-byte strings, depending on context.) $v = $ords[$i]; $str .= pack("N",$v); } $str = mb_convert_encoding($str,$encoding,"UCS-4BE"); return($str); } function unistr_to_ords($str, $encoding = 'UTF-8') { // Turns a string of unicode characters into an array of ordinal values, // Even if some of those characters are multibyte. $str = mb_convert_encoding($str,"UCS-4BE",$encoding); $ords = array(); // Visit each unicode character for ($i = 0; $i < mb_strlen($str,"UCS-4BE"); $i++) { // Now we have 4 bytes. Find their total // numeric value. $s2 = mb_substr($str,$i,1,"UCS-4BE"); $val = unpack("N",$s2); $ords[] = $val[1]; } return($ords); } function alphabet($firstCharacter = 'A', $lastCharacter = 'Z') { $firstCharacterValue = unistr_to_ords($firstCharacter)[0]; $lastCharacterValue = unistr_to_ords($lastCharacter)[0]; if ($firstCharacterValue < $lastCharacterValue) { for ($character = $firstCharacterValue; $character <= $lastCharacterValue; ++$character) { yield ords_to_unistr(array($character)); }; } else { for ($character = $firstCharacterValue; $character >= $lastCharacterValue; --$character) { yield ords_to_unistr(array($character)); }; } } foreach (alphabet('ا', 'ی') as $letter) { echo $letter, PHP_EOL; }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
ا ب ة ت ث ج ح خ د ذ ر ز س ش ص ض ط ظ ع غ ػ ؼ ؽ ؾ ؿ ـ ف ق ك ل م ن ه و ى ي ً ٌ ٍ َ ُ ِ ّ ْ ٓ ٔ ٕ ٖ ٗ ٘ ٙ ٚ ٛ ٜ ٝ ٞ ٟ ٠ ١ ٢ ٣ ٤ ٥ ٦ ٧ ٨ ٩ ٪ ٫ ٬ ٭ ٮ ٯ ٰ ٱ ٲ ٳ ٴ ٵ ٶ ٷ ٸ ٹ ٺ ٻ ټ ٽ پ ٿ ڀ ځ ڂ ڃ ڄ څ چ ڇ ڈ ډ ڊ ڋ ڌ ڍ ڎ ڏ ڐ ڑ ڒ ړ ڔ ڕ ږ ڗ ژ ڙ ښ ڛ ڜ ڝ ڞ ڟ ڠ ڡ ڢ ڣ ڤ ڥ ڦ ڧ ڨ ک ڪ ګ ڬ ڭ ڮ گ ڰ ڱ ڲ ڳ ڴ ڵ ڶ ڷ ڸ ڹ ں ڻ ڼ ڽ ھ ڿ ۀ ہ ۂ ۃ ۄ ۅ ۆ ۇ ۈ ۉ ۊ ۋ ی
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.

preferences:
212.39 ms | 408 KiB | 5 Q