I've been looking and searching for a long time now, but I can't find any way in PHP to grab a string such as "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" by telling it the input language or locale (not sure which is relevant... maybe both). In fact, I can't even find a non-PHP list of these online anywhere. Except for the USA.
Do I have to figure this out myself and then produce my own strings, or is this built into the language somehow and ready for me to "grab"?
If you know the first and last letter of your alphabet, it is possible to use a combination of mb_strtolower
and a mb_range
function I found here : GitHub rodneyrehm
$low_letters = mb_range('α', 'ω');
$upper_letters = array_map('mb_strtoupper', $low_letters);
echo implode('', array_merge($low_letters, $upper_letters)); // αβγδεζηθικλμνξοπρςστυφχψωΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΣΤΥΦΧΨΩ
And the code of the mb_range
function (in case the GitHub disappear) :
mb_internal_encoding('UTF-8');
/**
* multibyte string compatible range('A', 'Z')
*
* @param string $start Character to start from (included)
* @param string $end Character to end with (included)
* @return array list of characters in unicode alphabet from $start to $end
* @author Rodney Rehm
*/
function mb_range($start, $end) {
// if start and end are the same, well, there's nothing to do
if ($start == $end) {
return array($start);
}
$_result = array();
// get unicodes of start and end
list(, $_start, $_end) = unpack("N*", mb_convert_encoding($start . $end, "UTF-32BE", "UTF-8"));
// determine movement direction
$_offset = $_start < $_end ? 1 : -1;
$_current = $_start;
while ($_current != $_end) {
$_result[] = mb_convert_encoding(pack("N*", $_current), "UTF-8", "UTF-32BE");
$_current += $_offset;
}
$_result[] = $end;
return $_result;
}