#47164 [Opn->Asn]: uncomfortable (binary)char() append to binary string
| From: | johannes@php.net | Date: | Wed, 21 Jan 2009 16:24:58 +0000 |
| Subject: | #47164 [Opn->Asn]: uncomfortable (binary)char() append to binary string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-133115@lists.php.net to get a copy of this message | ||
ID: 47164
Updated by: johannes@php.net
Reported By: lunter at interia dot pl
-Status: Open
+Status: Assigned
Bug Type: Unicode Engine related
Operating System: all
PHP Version: 6CVS-2009-01-20 (snap)
-Assigned To:
+Assigned To: scottmac
New Comment:
Scott said he'd look into this :-)
Previous Comments:
------------------------------------------------------------------------
[2009-01-21 12:31:14] lunter at interia dot pl
johannes@php.net "(binary)chr($c) will give the wrong result"
hmmmmmmm....... try code above.
b1.dat consists utf-8 data
b2.dat consists binary chars 0 - 255 step 1, file length is correct -
256B & chars are correct...
<?
if(substr(phpversion(),0,1)!='6'){trigger_error('only PHP
6',E_USER_ERROR);}
// unicode.semantics = off
// unicode.runtime_encoding = iso-8859-1
// unicode.script_encoding = utf-8
// unicode.output_encoding = utf-8
// unicode.from_error_mode = U_INVALID_SUBSTITUTE
// unicode.from_error_subst_char = 3f
$b1=(binary)'';
for($z=0;$z<256;$z++){$b1.=chr($z);}
file_put_contents('b1.dat',$b1);
$b2=(binary)'';
for($z=0;$z<256;$z++){$b2.=(binary)chr($z);}
file_put_contents('b2.dat',$b2);
?>
------------------------------------------------------------------------
[2009-01-21 11:26:24] johannes@php.net
$b = sprintf("%c%c%c", 255, 254, 253);
should work, but having a simple function might still be helpful
------------------------------------------------------------------------
[2009-01-21 11:12:52] johannes@php.net
Actually we need a function doing "binary chr" - chr() in PHP 6 takes a
codepoint not the byte value, so (binary)chr($c) will give the wrong
result.
------------------------------------------------------------------------
[2009-01-20 10:59:03] lunter at interia dot pl
Description:
------------
uncomfortable (binary)char() append to a binary string
Reproduce code:
---------------
$b=(binary)'';
$b.=chr(255);
$b.=chr(254);
$b.=chr(253);
$b.=chr(252);
$b.=chr(251);
...
$b.=chr(0);
Expected result:
----------------
detect $b type as binary string and adding chr() in binary mode
like this:
$b=(binary)'';
$b.=(binary)chr(255);
$b.=(binary)chr(254);
$b.=(binary)chr(253);
$b.=(binary)chr(252);
$b.=(binary)chr(251);
...
$b.=(binary)chr(0);
Actual result:
--------------
adding chr() in unicode
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47164&edit=1