note 91868 modified in function.chr by danbrown

From: Date: Tue, 30 Jun 2009 13:14:01 +0000
Subject: note 91868 modified in function.chr by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157694@lists.php.net to get a copy of this message
The function chr() also accepts negative numbers as an ascii code, so chr(-number) is equal to chr((number%256)+256). And for ascii code higher than 255 is chr(number%256) We can test with a little script <?php for($i=-300; $i<300; $i++){ echo "Ascii $i\t" . ord(chr($i)) . "\n"; } ?> --was-- The function chr() also accepts negative numbers as an ascii code, so chr(-number) is equal to chr((number%256)+256). And for ascii code higher than 255 is chr(number%256) We can test with a little script <?php for($i=-300; $i<300; $i++){ echo "Ascii $i\t" . ord(chr($i)) . "\n"; } http://php.net/manual/en/function.chr.php

« previous php.notes (#157694) next »