#47480 [NEW]: preg_replace with "/i" is not case insensitive
| From: | sehh at ionos dot gr | Date: | Mon, 23 Feb 2009 13:32:40 +0000 |
| Subject: | #47480 [NEW]: preg_replace with "/i" is not case insensitive | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-134113@lists.php.net to get a copy of this message | ||
From: sehh at ionos dot gr
Operating system: Linux
PHP version: 5.2.8
PHP Bug Type: *Regular Expressions
Bug description: preg_replace with "/i" is not case insensitive
Description:
------------
preg_replace with the "/i" (case insensitive search) does not do a case
insensitive search for UTF-8 Greek characters, while it works fine for
English characters.
Reproduce code:
---------------
<?php
$string = "Ôï êõñßùò ôìÞìá ôïõ êéíçôÞñá, áõôü ðïõ
ðåñéëáìâÜíåé ôïõò
êõëßíäñïõò"; // UTF-8 string in Greek language
$target1 = "ÊÉÍÇÔÇÑÁ"; // Target string to search for (capitalized)
$target2 = "êéíçôÞñá"; // Target string to search for (small letters)
$replace = "itworks"; // Replace with this string
$rc = preg_replace("/$target1/imsUu", $replace, $string, -1, $counter); //
Execute search for target1 and replace
echo "\nSearching for: ".$target1."\n"; // Report output
echo "Result string: ".$rc."\n";
echo "Found and replaced: ".$counter."\n";
$rc = preg_replace("/$target2/imsUu", $replace, $string, -1, $counter); //
Execute search for target2 and replace
echo "\nSearching for: ".$target2."\n"; // Report output
echo "Result string: ".$rc."\n";
echo "Found and replaced: ".$counter."\n\n";
?>
Expected result:
----------------
I expect the Found and Replaced to be both "1" since the expression is not
case sensitive.
Actual result:
--------------
$ php -f test.php
Searching for: ÊÉÍÇÔÇÑÁ
Result string: Ôï êõñßùò ôìÞìá ôïõ êéíçôÞñá, áõôü ðïõ
ðåñéëáìâÜíåé ôïõò
êõëßíäñïõò
Found and replaced: 0
Searching for: êéíçôÞñá
Result string: Ôï êõñßùò ôìÞìá ôïõ itworks, áõôü ðïõ ðåñéëáìâÜíåé
ôïõò
êõëßíäñïõò
Found and replaced: 1
--
Edit bug report at http://bugs.php.net/?id=47480&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47480&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47480&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47480&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47480&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47480&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47480&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47480&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47480&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47480&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47480&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47480&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47480&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47480&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47480&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47480&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47480&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47480&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47480&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47480&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47480&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47480&r=mysqlcfg