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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: floyd dot mcmichael at alaska dot gov
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2021 The PHP Group
All rights reserved.
Last updated: Tue Dec 07 15:03:33 2021 UTC