#39853 [Opn]: strtoupper(), strtolower() function can not work with preg_replace $1 vars

2006-12-16 Thread anton dot kirsanov at gmail dot com
 ID:   39853
 User updated by:  anton dot kirsanov at gmail dot com
 Reported By:  anton dot kirsanov at gmail dot com
 Status:   Open
 Bug Type: Strings related
 Operating System: Windows XP SP2
 PHP Version:  4.4.4
 New Comment:

Sorry, am mix up a 'Expected result' and 'Actual result' :)
Please read this quite the contrary - 'Expected result' is a 'Actual
result'.


Previous Comments:


[2006-12-16 12:35:36] ara at lenta dot ru

#1090;#1099; #1093;#1091;#1081;



[2006-12-16 12:33:44] 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





-- 
Edit this bug report at http://bugs.php.net/?id=39853edit=1


#39853 [Opn]: strtoupper(), strtolower() function can not work with preg_replace $1 vars

2006-12-16 Thread anton dot kirsanov at gmail dot com
 ID:   39853
 User updated by:  anton dot kirsanov at gmail dot com
 Reported By:  anton dot kirsanov at gmail dot com
 Status:   Open
 Bug Type: Strings related
 Operating System: Windows XP SP2
 PHP Version:  4.4.4
 New Comment:

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

Why?

See that:

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

// --
// ACTUAL RESULT:
// --
   ABB

// Why that ? :)


Previous Comments:


[2006-12-16 18:09:15] 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 12:40:44] ara at lenta dot ru

Tu XYu.



[2006-12-16 12:37:46] 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:35:36] ara at lenta dot ru

#1090;#1099; #1093;#1091;#1081;



[2006-12-16 12:33:44] 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





-- 
Edit this bug report at http://bugs.php.net/?id=39853edit=1