note 116052 added to function.range

From: Date: Mon, 03 Nov 2014 19:55:50 +0000
Subject: note 116052 added to function.range
Groups: php.notes 
Request: Send a blank email to php-notes+get-200777@lists.php.net to get a copy of this message
Range appears to follow the ascii code table definitions as with chr() and ord(), despite it not being documented. It iterates over ord($chr1) through ord($char2) using a simple for loop and can also be used with symbols because of this. So ord('!') and ord('/') would iterate over chr() from 33 to 47, like so: <?php var_dump(range('!', '/')); //array('!','"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/'); var_dump(range(':', '@')); //array(':', ';', '<', '=', '>', '?', '@'); var_dump(range('[', '`')); //array('[', '\', ']', '^', '_', '`'); //To list all of the general ascii codes (including space) (32 to 126) one can execute. var_dump(range(' ', '~')); //array(' ', '!', '"', '#', '$', '%', '&', ''', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~'); ?> It can also be used in reverse order. range('~', ' '); Tested above in php 4.3 - 5.6.2 Additionally for extended ascii codes, when tested using a for loop of ord($char1) to ord($chr2) in comparison with range(chr(128), chr(255)) ('€', 'ÿ') they produced the same results. Be sure your character encoding is set appropriately. <?php var_dump(range(chr(128), chr(255))); $array = array(); for ($i = 128; $i <= 255; $i++) { $array[] = chr($i); } var_dump($array); ?> ---- Server IP: 72.52.91.14 Probable Submitter: 50.79.80.225 ---- Manual Page -- http://php.net/manual/en/function.range.php Edit -- https://master.php.net/note/edit/116052 Del: integrated -- https://master.php.net/note/delete/116052/integrated Del: useless -- https://master.php.net/note/delete/116052/useless Del: bad code -- https://master.php.net/note/delete/116052/bad+code Del: spam -- https://master.php.net/note/delete/116052/spam Del: non-english -- https://master.php.net/note/delete/116052/non-english Del: in docs -- https://master.php.net/note/delete/116052/in+docs Del: other reasons-- https://master.php.net/note/delete/116052 Reject -- https://master.php.net/note/reject/116052 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200777) next »