php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79986 str_ireplace bug with diacritics characters
Submitted: 2020-08-17 18:03 UTC Modified: 2020-08-18 11:31 UTC
From: cryptooman at yandex dot ru Assigned: cmb (profile)
Status: Closed Package: Strings related
PHP Version: 7.2.33 OS: *
Private report: No CVE-ID: None
 [2020-08-17 18:03 UTC] cryptooman at yandex dot ru
Description:
------------
---
From manual page: https://php.net/function.str-ireplace
---
Function str_ireplace fails to replace diacritics characters if case (lower or upper) of search pattern does not match case of characters in subject string. Affected languages: french, russian, german, spanish, etc. Short php-script sample provided below.



Test script:
---------------
<?php
// French
// Result: 1À 2Â 3Ä 4Æ
// Expect: 11 22 33 44
echo str_ireplace(['à', 'â', 'ä', 'æ'], ['1', '2', '3', '4'], 'àÀ â äÄ æÆ') . PHP_EOL;
// Result: à1 â2 ä3 æ4
// Expect: 11 22 33 44
echo str_ireplace(['À', 'Â', 'Ä', 'Æ'], ['1', '2', '3', '4'], 'àÀ â äÄ æÆ') . PHP_EOL;

// Russian
// Result: 1Ё 2Й
// Expect: 11 22
echo str_ireplace(['ё', 'й'], ['1', '2'], 'ёЁ йЙ') . PHP_EOL;
// Result: ё1 й2
// Expect: 11 22
echo str_ireplace(['Ё', 'Й'], ['1', '2'], 'ёЁ йЙ') . PHP_EOL;


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-18 10:19 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: *General Issues +Package: Strings related
 [2020-08-18 10:19 UTC] cmb@php.net
Actually, str_ireplace() (like several other string functions) is
supposed to be locale aware, but only supporting single byte
locales properly; this is not documented yet.

The implementation doesn't match that expectation, though[1].

Anyhow, assuming that you're dealing with UTF-8, you may want to
use preg_replace() instead[2].

[1] <https://3v4l.org/GVECA>
[2] <https://3v4l.org/2D4ZJ>
 [2020-08-18 11:29 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2020-08-18 11:30 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #79986: str_ireplace bug with diacritics characters
On GitHub:  https://github.com/php/php-src/pull/6007
Patch:      https://github.com/php/php-src/pull/6007.patch
 [2020-08-18 11:31 UTC] cmb@php.net
-Operating System: Ubuntu 18.04 +Operating System: *
 [2020-08-24 09:10 UTC] cmb@php.net
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=844a2dd6ac9e411e4f24d3a0beab9a23e820325c
Log: Fix #79986: str_ireplace bug with diacritics characters
 [2020-08-24 09:10 UTC] cmb@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 18:01:29 2024 UTC