php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43872 preg_replace() returns blank string
Submitted: 2008-01-16 23:45 UTC Modified: 2008-01-17 19:18 UTC
From: floyd dot mcmichael at alaska dot gov Assigned:
Status: Closed Package: *Regular Expressions
PHP Version: 5.2.5 OS: windows
Private report: No CVE-ID: None
 [2008-01-16 23:45 UTC] 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 ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-16 23:52 UTC] 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-17 19:18 UTC] floyd dot mcmichael at alaska dot gov
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC