#43872 [Opn->Csd]: preg_replace() returns blank string

From: Date: Thu, 17 Jan 2008 19:18:55 +0000
Subject: #43872 [Opn->Csd]: preg_replace() returns blank string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121370@lists.php.net to get a copy of this message
ID: 43872 User updated by: floyd dot mcmichael at alaska dot gov Reported By: floyd dot mcmichael at alaska dot gov -Status: Open +Status: Closed Bug Type: *Regular Expressions Operating System: windows PHP Version: 5.2.5 New Comment: reviewed preg_replace string again and realized two non-alphanumeric characters were not escaped. (specifically two "(" ) re-ran and now the preg_replace string works. this must have been a change in 5.2.5 but now that the ('s are escaped the function works properly. Previous Comments: ------------------------------------------------------------------------ [2008-01-16 23:52:00] floyd dot mcmichael at alaska dot gov EDIT: "<img src=\"./skin/$skinname/emotes/crazy.png\" src=\"./skin/$skinname/emotes/crazy.png\" alt=\"crazy\" title=\"crazy\">" should be "<img src=\"./skin/$skinname/emotes/crazy.png\" alt=\"crazy\" title=\"crazy\">" preg_last_error(); returns 0 NO_ERROR. why is this function not working as expected? ------------------------------------------------------------------------ [2008-01-16 23:45:51] floyd dot mcmichael at alaska dot gov Description: ------------ preg_replace blanks a string that it didn't use to in previous versions of PHP 5.x. other preg_replace strings not affected Reproduce code: --------------- function doSmiles($string, $skinname) { $patterns = array( "/\[alien\]/i", ... snipped due to length ... "/\[crazy\]/i" ); $replacements = array( "<img src=\"./skin/$skinname/emotes/alien.png\" alt=\"alien\" title=\"alien\">", ... snip due to length ... "<img src=\"./skin/$skinname/emotes/crazy.png\" src=\"./skin/$skinname/emotes/crazy.png\" alt=\"crazy\" title=\"crazy\">" ); $string = preg_replace($patterns, $replacements, $string); return $string; } Expected result: ---------------- print substrings like [alien] to html-valid strings like <img src="./skin/default/alien.png">. prior to upgrading to 5.2.5 this particular function DID work. it no longer works. Actual result: -------------- returns a blank string "" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43872&edit=1

« previous php.bugs (#121370) next »