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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC