php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49459 Use of case changing functions in preg_replace produces unexpected results
Submitted: 2009-09-03 16:00 UTC Modified: 2009-09-03 21:58 UTC
From: d dot reade at readesresidential dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.2.10 OS: CentOS 5.3 x86
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: d dot reade at readesresidential dot com
New email:
PHP Version: OS:

 

 [2009-09-03 16:00 UTC] d dot reade at readesresidential dot com
Description:
------------
Trying to use preg_replace to change text to uppercase in-between <uc><uc>. However expected result doesn't occur and the text remains lowercase. No errors are logged. However adding some text after $1 outputs this text in uppercase, but the text in-between <uc><uc> remains as lowercase.

Reproduce code:
---------------
<?
# Test 1: Attempt to replace 'my' with 'MY'
$text	=	'this is <uc>my<uc> string';
$text	=	preg_replace('/\<uc\>(.*)\<uc\>/', strtoupper('$1'), $text);
echo $text.'<br><br>';

# Test 2: Add something after $1 which produces expected output
$text	=	'this is <uc>my<uc> string';
$text	=	preg_replace('/\<uc\>(.*)\<uc\>/', strtoupper('$1 cool'), $text);
echo $text;
?>

Expected result:
----------------
# Expected result for test 1
this is MY string

# Expected result for test 2
this is MY COOL string

Actual result:
--------------
# Actual result for test 1
this is my string

# Actual result for test 2
this is my COOL string

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-03 21:04 UTC] jani@php.net
Your forgot to RTFM:

http://www.php.net/manual/en/function.preg-replace.php

Hint: Example #4
 [2009-09-03 21:58 UTC] d dot reade at readesresidential dot com
Ah I see, sorry, my bad.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat May 28 17:05:46 2022 UTC