Bug #79118 [Com]: mb_ereg_replace function cannot replace strings

From: Date: Wed, 15 Jan 2020 06:21:34 +0000
Subject: Bug #79118 [Com]: mb_ereg_replace function cannot replace strings
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224905@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79118&edit=1 ID: 79118 Comment by: minhlt82 at gmail dot com Reported by: minhlt82 at gmail dot com Summary: mb_ereg_replace function cannot replace strings Status: Not a bug Type: Bug Package: mbstring related Operating System: Linux PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: Thanks for the reply. I packed the characters to create emoji and then displayed on some phones in Japan. The problem I am wondering is that it works fine with php 7.0.14 and earlier. I think there are several changes from version 7.1 that cause this problem. Previous Comments: ------------------------------------------------------------------------ [2020-01-15 04:43:41] requinix@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. You cannot pass raw binary data to something that operates on characters. I don't know what 63735 means to you, I don't know why you're packing it, and I can't fathom why you're inserting that packed data into a human-readable string, but I do know that you can't put the bytes 0xF8F7 into a string and then safely convert it to any other encoding. My first thought is that you need to use some sort of string templating system, as is typically done with i18n translations. ------------------------------------------------------------------------ [2020-01-15 03:29:02] minhlt82 at gmail dot com @Requinix: Thank you for the super fast support. For the replacement of the binary string, following your link https://3v4l.org/ofV7G I am still facing a problem that the hex value of binary string before and after the conversion (by mb_convert_encoding)is changed from f8f7 to 3fc3b7. Could you please help me to check here https://3v4l.org/JE5r8 Thank you so much. ------------------------------------------------------------------------ [2020-01-15 02:22:22] requinix@php.net Seems to be working fine. https://3v4l.org/Z575v https://3v4l.org/ofV7G Because you can't pass raw binary data to something that operates on characters. ------------------------------------------------------------------------ [2020-01-15 02:00:31] minhlt82 at gmail dot com Description: ------------ The mb_ereg_replace function cannot replace strings that contain some characters with the SJIS encoding. In these cases, the result is NULL. It works well with PHP versions < 7.1 but fails with PHP 7.1 and above. Test script: --------------- mb_regex_encoding('SJIS'); $string = "hello ここに文を入れる。"; $pattern = "hello"; $replacement = 'hi'; //expected result: hi ここに文を入れる。 //but it returns NULL var_dump(mb_ereg_replace($pattern, $replacement, $string)); //Similar error for binary strings, you can test more here. //http://sandbox.onlinephpfunctions.com/code/1a741afb48b299c6f335d9175be730a5ec3854d5 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79118&edit=1

« previous php.bugs (#224905) next »