|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-01 14:39 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 14:00:01 2025 UTC |
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.