php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76158 UTF-8 character C29D handling
Submitted: 2018-03-28 12:13 UTC Modified: 2018-03-28 12:23 UTC
From: miloslav dot hula at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2018-03-28 12:13 UTC] miloslav dot hula at gmail dot com
Description:
------------
I expected that I can split any string to single octects, but it does not work for UTF-8 character C29D

https://3v4l.org/FjUb7

Test script:
---------------
<?php

$ch = "\xc2\x9d";
foreach (str_split($ch) as $c) {
    echo sprintf("0x%02X", $c) . "\n";
}


Expected result:
----------------
0xC2
0x9D

Actual result:
--------------
0x00
0x00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-03-28 12:16 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2018-03-28 12:16 UTC] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

http://php.net/manual/en/function.sprintf.php
> X - the argument is treated as an integer and presented as a hexadecimal number (with uppercase letters).

Use ord($c).
 [2018-03-28 12:23 UTC] miloslav dot hula at gmail dot com
Sorry, I'm idiot.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 16:01:29 2024 UTC