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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 07:01:27 2024 UTC