php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42949 range('a', 'Z') has weird results
Submitted: 2007-10-12 13:49 UTC Modified: 2007-10-12 17:56 UTC
From: phpbug at fint dot org Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.4 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: phpbug at fint dot org
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-12 16:17 UTC] felipensp at gmail dot com
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";

?>
 [2007-10-12 17:56 UTC] phpbug at fint dot org
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
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 19:01:35 2025 UTC