php-src
php-src copied to clipboard
mb_convert_encoding returns empty string since PHP 8.1.0
Description
The following code:
<?php
$str = 'Test';
# Make sure string is in UTF-8 and strip invalid UTF-8 characters
$str = mb_convert_encoding($str, 'UTF-8', mb_list_encodings());
print_r($str);
Resulted in this output:
But I expected this output instead:
Test
This code is from a gist we use https://gist.github.com/sgmurphy/3098978
PHP Version
PHP 8.1.0
Operating System
CentOS 7
I can confirm this for PHP 8.1.1, but it looks like the issue has been fixed with f07c1935839bf87e9d5a26a82a0ed8747c4f178f, which is contained in PHP 8.1.2RC1. Could you please check with that pre-release?
[root@RO ~]# php81 -v
PHP 8.1.2RC1 (cli) (built: Jan 4 2022 18:35:06) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.2RC1, Copyright (c) Zend Technologies
[root@RO ~]# php81 -r 'print_r(mb_convert_encoding("Test", "UTF-8", mb_list_encodings()));'
Test
I can confirm that it's fixed🚀