|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-10-12 13:49 UTC] phpbug at fint dot org
Description:
------------
range('a', 'Z') gives random junk
Reproduce code:
---------------
<?php
foreach (range('a', 'Z') as $letter) {
echo $letter;
}
?>
Expected result:
----------------
a-z and A-Z (wishful thinking?)
I am trying to recreate Perl's "@a=('a'..'z', 'A'..'Z');"
Actual result:
--------------
a`_^]\[Z
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 02:00:01 2025 UTC |
The order is A-Z, a-z. <?php $init = ord('A'); $end = ord('z'); printf("Init.: %d | End.: %d\n", $init, $end); for ($i = $init; $i <= $end; $i++) { print chr($i); } print "\n"; ?>Apparently it also has non-alpha characters in it, which is why I was confused. <?php foreach (range('A', 'z') as $letter) { echo $letter; } ?> Yields: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz