#45675 [Opn->Bgs]: The documentation for ord() is inaccurate

From: Date: Mon, 04 Aug 2008 12:42:10 +0000
Subject: #45675 [Opn->Bgs]: The documentation for ord() is inaccurate
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1051@lists.php.net to get a copy of this message
ID: 45675 Updated by: rquadling@php.net Reported By: mtesta at money-media dot com -Status: Open +Status: Bogus Bug Type: Documentation problem Operating System: Windows XP PHP Version: Irrelevant New Comment: At the windows command line ... php -r "echo ord('Å¡');" I get 154. If the file is encoded Windows 1252 I get 154. Latin small letter s with caron. If the file is encoded UTF-8, I get 197 as ord() is working on binary strings and Å¡ has a binary value of 0xC5 0xA1 an 0xC5 = 197. (This translates to U+0161 according to Charmap). In PHP 5, ord() currently works on binary strings. So, depending upon the encoding used, the binary string may start whatever is appropriate. There is a user note on ord() with regards to getting a value of a unicode "character". This returns a value of 353 which, as if by magic, has a value of 0x0161. Previous Comments: ------------------------------------------------------------------------ [2008-08-01 14:39:41] mtesta at money-media dot com Description: ------------ The documentation for ord() is inaccurate. From my tests ord() returns the ANSI (Windows-1252) value of character. Bellow is a simple test to confirm this. "š" is not in the ASCII character set but the value of "š" in the ANSI character set is 154. Reproduce code: --------------- ord('š'); Actual result: -------------- 154 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45675&edit=1

« previous php.doc.bugs (#1051) next »