#45675 [Bgs]: The documentation for ord() is inaccurate
| From: | mtesta at money-media dot com | Date: | Mon, 04 Aug 2008 13:01:07 +0000 |
| Subject: | #45675 [Bgs]: The documentation for ord() is inaccurate | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1056@lists.php.net to get a copy of this message | ||
ID: 45675
User updated by: mtesta at money-media dot com
Reported By: mtesta at money-media dot com
Status: Bogus
Bug Type: Documentation problem
Operating System: Windows XP
PHP Version: Irrelevant
New Comment:
I'm not talking about the user notes or about the accuracy of the
function. The function works absolutely fine. In fact, I'm glad it works
the way it does. I'm just saying that the documentation is miss leading.
The ASCII character set only goes from 0 to 127. When I read the
documentation and it tells me that ord returns the ASCII value that
tells me to only expect a return value between 0 and 127 (or 32 to 126
for printable characters).
I have no problems with the way the ord function works. Only the
documentation does not reflect what the function does.
Previous Comments:
------------------------------------------------------------------------
[2008-08-04 12:54:41] rquadling@php.net
The only thing that is potentially missing is that you will get a
different response depending upon the encoding of the source file.
If you use UTF-8, the first byte (which in PHP5 and lower is synonymous
with character) has a value of 197.
If you are using Windows-1252, then the character has a value of 154.
Both are correct as they are in effect different strings.
If you are needing UTF-8 string processing, then the functions
mentioned in the user notes as well as other multi-byte string libraries
are available.
------------------------------------------------------------------------
[2008-08-04 12:47:05] mtesta at money-media dot com
That's exactly my point. The PHP documentation
(http://us.php.net/manual/en/function.ord.php) says: "Returns the ASCII
value of the first character of string". This is not true, as we have
both shown, and should be updated appropriately.
------------------------------------------------------------------------
[2008-08-04 12:42:08] rquadling@php.net
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.
------------------------------------------------------------------------
[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