|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-03-20 19:58 UTC] tony2001@php.net
[2007-03-20 20:00 UTC] ismith at motorola dot com
[2007-03-20 20:03 UTC] ismith at motorola dot com
[2007-03-20 20:16 UTC] tony2001@php.net
[2007-03-21 17:45 UTC] ismith at motorola dot com
[2007-03-21 22:47 UTC] tony2001@php.net
[2007-03-22 00:29 UTC] andrei@php.net
[2007-03-22 23:03 UTC] nlopess@php.net
[2007-04-26 09:14 UTC] tony2001@php.net
[2007-04-26 16:26 UTC] andrei@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 00:00:02 2025 UTC |
Description: ------------ I am using preg_replace to do a search and replace on some text which contains an invalid UTF-8 code sequence. I am using the "u" modifier. I believe that preg_replace should suppress the bad character, or replace it with an appropriate error marker; but otherwise return the text intact (after making the required replacements). Both preg_replace and preg_replace_callback return an empty string in this case, even when the search pattern matches nothing in the input. Reproduce code: --------------- <?php // Text with a valid UTF-8 character sequence. $goodText = "I hate WOMBATS \342\200\234 and COWS"; // Text with an invalid UTF-8 character sequence. $badText = "I love BEARS \342\200\077 and LIONS"; $good2 = preg_replace("/ELEPHANTS/iu", "MICE", $goodText); printf("Was \"%s\"; now \"%s\"\n", $goodText, $good2); $bad2 = preg_replace("/ELEPHANTS/iu", "MICE", $badText); printf("Was \"%s\"; now \"%s\"\n", $badText, $bad2); ?> Expected result: ---------------- Was "I hate WOMBATS Γǣ and COWS"; now "I hate WOMBATS Γǣ and COWS" Was "I love BEARS Γ?? and LIONS"; now "I love BEARS Γ?? and LIONS" Actual result: -------------- Was "I hate WOMBATS Γǣ and COWS"; now "I hate WOMBATS Γǣ and COWS" Was "I love BEARS Γ?? and LIONS"; now ""