#49459 [Bgs]: Use of case changing functions in preg_replace produces unexpected results
| From: | d dot reade at readesresidential dot com | Date: | Thu, 03 Sep 2009 21:58:35 +0000 |
| Subject: | #49459 [Bgs]: Use of case changing functions in preg_replace produces unexpected results | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-141939@lists.php.net to get a copy of this message | ||
ID: 49459
User updated by: d dot reade at readesresidential dot com
Reported By: d dot reade at readesresidential dot com
Status: Bogus
Bug Type: PCRE related
Operating System: CentOS 5.3 x86
PHP Version: 5.2.10
New Comment:
Ah I see, sorry, my bad.
Previous Comments:
------------------------------------------------------------------------
[2009-09-03 21:04:46] jani@php.net
Your forgot to RTFM:
http://www.php.net/manual/en/function.preg-replace.php
Hint: Example #4
------------------------------------------------------------------------
[2009-09-03 16:00:23] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=49459&edit=1