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
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: 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

Pull Requests

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: Mon Dec 30 14:01:28 2024 UTC