php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39853 strtoupper(), strtolower() function can not work with preg_replace $1 vars
Submitted: 2006-12-16 12:33 UTC Modified: 2006-12-17 13:11 UTC
Votes:2
Avg. Score:1.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: anton dot kirsanov at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 4.4.4 OS: Windows XP SP2
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: anton dot kirsanov at gmail dot com
New email:
PHP Version: OS:

 

 [2006-12-16 12:33 UTC] anton dot kirsanov at gmail dot com
Description:
------------
strtoupper(), strtolower() function does not change 
string(as virtual vars - like $1(\\1)) what be returned a preg_replace function.


Reproduce code:
---------------
<?php
// 1
$s = "A-B";
echo preg_replace("/\-([a-z])/iU", strtolower("$1"), $s);

echo "\n";

// 2
$s = "a-b";
echo preg_replace("/\-([a-z])/iU", strtoupper("$1"), $s);

// 3

$s = "B-B";
echo preg_replace("/([a-z]-[a-z])/i", strtolower("A-$1-A"), $s);


?>

Expected result:
----------------
AB
ab
a-B-B-a

Actual result:
--------------
Ab
aB
abba

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-16 12:35 UTC] ara at lenta dot ru
&#1090;&#1099; &#1093;&#1091;&#1081;
 [2006-12-16 12:37 UTC] anton dot kirsanov at gmail dot com
Sorry, am mix up a 'Expected result' and 'Actual result' :)
Please read this quite the contrary - 'Expected result' is a 'Actual result'.
 [2006-12-16 12:40 UTC] ara at lenta dot ru
Tu XYu.
 [2006-12-16 18:09 UTC] judas dot iscariote at gmail dot com
Why you think this is a bug ?

you are looking for preg_replace_callback ... or if you are crazy, the preg_replace "/e" modifier.

not a bug, read the manual ;-)
 [2006-12-16 20:48 UTC] anton dot kirsanov at gmail dot com
Hi:)
funny...
you will use "/e" modifier if you want parse the pattern as a php code. 
Say me, why a function str_repeat() really work in this situation:
<?php
 $s = "A-B";
 echo preg_replace("/\-([a-z])/iU", str_repeat("$1", 10), $s);
?>

// --------------
// ACTUAL RESULT:
// --------------
   ABBBBBBBBBB

Why?

See that:

<?php
 $s = "A-B";
 echo preg_replace("/\-([a-z])/iU", strtolower(str_repeat("$1", 10)), $s);
?>

// --------------
// ACTUAL RESULT:
// --------------
   ABBBBBBBBBB

// Why that ? :)
 [2006-12-17 13:11 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 09:01:29 2024 UTC