php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75225 Add mb_str_replace/mb_str_ireplace
Submitted: 2017-09-18 14:20 UTC Modified: 2017-09-18 14:33 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 1234ru at gmail dot com Assigned:
Status: Open Package: mbstring related
PHP Version: 7.1.9 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 1234ru at gmail dot com
New email:
PHP Version: OS:

 

 [2017-09-18 14:20 UTC] 1234ru at gmail dot com
Description:
------------
In other words, it simply ignores case-insensitive replacement when dealing with any letters except Latin. 

Not a single word in the documentation at http://php.net/str_ireplace covers the issue.
And there is no corresponding mb* function. 

Test script:
---------------
echo str_ireplace("б", "1", "111ббб"); // russian letters in UTF-8 encoding

Expected result:
----------------
111111

Actual result:
--------------
111ббб

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-18 14:27 UTC] 1234ru at gmail dot com
An actual example is this:

echo str_ireplace("Б", "1", "БББббб"); 
// yelds 111ббб instead of 111111

(It doesn't allow me to edit the bug description so I post it as a comment.)
 [2017-09-18 14:28 UTC] spam2 at rhsoft dot net
this is NOT a bug - most of the string funtion don't work for UTF8 at all and be warned about making decisions about strlen() on UTF8 strings

http://php.net/manual/en/book.mbstring.php
 [2017-09-18 14:29 UTC] requinix@php.net
-Summary: str_ireplace() has no case insensitivity on non-latin letters in UTF strings +Summary: Add mb_str_replace/mb_str_ireplace -Type: Bug +Type: Feature/Change Request -Package: *Languages/Translation +Package: mbstring related
 [2017-09-18 14:29 UTC] requinix@php.net
Virtually all of the regular string functions are not for multibyte encodings.
 [2017-09-18 14:33 UTC] cmb@php.net
str_ireplace() regards the currently set locale, see <https://3v4l.org/AaXAm>,
but apparently that is not mentioned in the documentation.
 [2017-09-29 22:28 UTC] 1234ru at gmail dot com
> spam2 at rhsoft dot net
> this is NOT a bug - most of the string funtion don't work for UTF8
> http://php.net/manual/en/book.mbstring.php

Yes. But there is no mb_str_replace().

> str_ireplace() regards the currently set locale, see <https://3v4l.org/AaXAm>,
> but apparently that is not mentioned in the documentation.

Yes. That's the very problem. str_replace() works with no explicit LC_ALL setting, but str_ireplace() doesn't. That is rather misleading. I guess this should be mentioned in the docs.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 05:01:26 2019 UTC