|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-06-04 08:34 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
Description: ------------ Hello, the problem is, on this specific string (which I managed to write by accident) preg_replace returns NULL, not the unmodified string (because the regexp isn't matched). The funny thing is, if I remove some chars from the end of the string, or if I remove all "[quote]" ocurences from the search string, or if I provide a closing tag for the quote ([/quote]) - it works ok (returns the original string). And this bug (as I see it) is found only in PHP 5.2.*. My current sysinfo: Windows XP sp2 PHP 5.2.3 as Apache2.2 cli (from binary .zip) PCRE Library Version 7.0 18-Dec-2006 PHP versions I tested it on: 5.2.3 - bad 5.2.1 - bad 5.2.0 - bad 5.1.6 - ok, returns the string 4.3.10 - ok 4.3.2 - ok It works the same on linux and windows. Reproduce code: --------------- <?php header("Content-type: text/html; charset=utf-8"); ?> <pre> <?php //base64_encoded, because it's UTF-8, Lithuanian $string = base64_decode("VcW+ZHJhdXN0YSBmb3J1bXVvc2UgcmHFoXl0aSBjaXRhdMWzIHBha2xvZGVz". "IC0gdC55LiwgamVpZ3UgcmHFoXlzaXRlIDMtaXItZGF1Z2lhdSBuZQ0KdcW+ZGFyeXRhcyBjaW". "F0YXRhcyAoW3F1b3RlXS4uLltxdW90ZV0uLi5bcXVvdGVdLi4uKSwgdGFpIGp1bXMgYnVzIGFw". "aWUgdGFpIHByYW5lxaF0YSBpciDFvmludQ0KdMSXIG5lYnVzIGnFoXNpxbNzdGEgLSBz"); echo "The string is:\n".$string."\n\n"; echo "PHP: ".phpversion()."\n"; $regexp = "/\[quote\]((\s|.)*)\[\/quote\]/i"; echo (preg_match($regexp, $string) == true ? "Match found\n" : "Match not found\n"). "var_dump( preg_replace(...) ): "; var_dump( preg_replace($regexp, "<span style='background_color: yellow;'>\$1</span>", $string) ); ?> </pre> Expected result: ---------------- var_dump( preg_replace(...) ): <The original string> Actual result: -------------- var_dump( preg_replace(...) ): NULL