[PHP] preg_replace is modifying the type of replacement parameter !!

2001-09-11 Thread Nicolas Guilhot

Hi guys,

When I use preg_replace with an array of integer as the replacement
parameter, this function modifies the type of each array element to string.
I don't understand why it alters the content of the array while this
variable is not pass by reference (True or not ??).

I have just upgraded to PHP 4.0.6 and it I don't think it was the case in
PHP 4.0.4 (the version I was using before, without this problem).

Here is a short example that demonstrate my problem.

?php
$ary_pattern = array(@One@);
$ary_replace = array(1);
$string_before =  One example;
echo gettype($ary_replace[0]); // This line outputs 'integer'
$string_after = preg_replace($ary_pattern, $ary_replace, $string_before);
echo br$string_afterbr;
echo gettype($ary_replace[0]); // This line outputs 'string'
?

Is this a bug from preg_replace or am I doing wrong somewhere? Any help
would be appreciated.
Regards.

Nicolas Guilhot


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] preg_replace is modifying the type of replacement parameter !!

2001-09-11 Thread Andrey Hristov

Hmmm, RegEx work on strings, so the engine needs strings. Because of that your 
integers are converted to strings, if you want to
give their life back make
foreach ($arr as $k=$v){
$arr[$k]+=0;
}
Now all are integers.

Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS


- Original Message -
From: Nicolas Guilhot [EMAIL PROTECTED]
To: Php General MailingList [EMAIL PROTECTED]
Sent: Tuesday, September 11, 2001 3:24 PM
Subject: [PHP] preg_replace is modifying the type of replacement parameter !!


 Hi guys,

 When I use preg_replace with an array of integer as the replacement
 parameter, this function modifies the type of each array element to string.
 I don't understand why it alters the content of the array while this
 variable is not pass by reference (True or not ??).

 I have just upgraded to PHP 4.0.6 and it I don't think it was the case in
 PHP 4.0.4 (the version I was using before, without this problem).

 Here is a short example that demonstrate my problem.

 ?php
 $ary_pattern = array(@One@);
 $ary_replace = array(1);
 $string_before =  One example;
 echo gettype($ary_replace[0]); // This line outputs 'integer'
 $string_after = preg_replace($ary_pattern, $ary_replace, $string_before);
 echo br$string_afterbr;
 echo gettype($ary_replace[0]); // This line outputs 'string'
 ?

 Is this a bug from preg_replace or am I doing wrong somewhere? Any help
 would be appreciated.
 Regards.

 Nicolas Guilhot


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] preg_replace is modifying the type of replacement parameter !!

2001-09-11 Thread Nicolas Guilhot

I understand that RegEx works on strings, but I don't understand why this
function modifies the replacement parameter as it is not pass by-reference.

Nicolas

-Message d'origine-
De : Andrey Hristov [mailto:[EMAIL PROTECTED]]
Envoyé : mardi 11 septembre 2001 14:34
À : [EMAIL PROTECTED]
Objet : Re: [PHP] preg_replace is modifying the type of replacement
parameter !!


Hmmm, RegEx work on strings, so the engine needs strings. Because of that
your integers are converted to strings, if you want to
give their life back make
foreach ($arr as $k=$v){
$arr[$k]+=0;
}
Now all are integers.

Andrey Hristov
IcyGEN Corporation
http://www.icygen.com
BALANCED SOLUTIONS


- Original Message -
From: Nicolas Guilhot [EMAIL PROTECTED]
To: Php General MailingList [EMAIL PROTECTED]
Sent: Tuesday, September 11, 2001 3:24 PM
Subject: [PHP] preg_replace is modifying the type of replacement parameter
!!


 Hi guys,

 When I use preg_replace with an array of integer as the replacement
 parameter, this function modifies the type of each array element to
string.
 I don't understand why it alters the content of the array while this
 variable is not pass by reference (True or not ??).

 I have just upgraded to PHP 4.0.6 and it I don't think it was the case in
 PHP 4.0.4 (the version I was using before, without this problem).

 Here is a short example that demonstrate my problem.

 ?php
 $ary_pattern = array(@One@);
 $ary_replace = array(1);
 $string_before =  One example;
 echo gettype($ary_replace[0]); // This line outputs 'integer'
 $string_after = preg_replace($ary_pattern, $ary_replace, $string_before);
 echo br$string_afterbr;
 echo gettype($ary_replace[0]); // This line outputs 'string'
 ?

 Is this a bug from preg_replace or am I doing wrong somewhere? Any help
 would be appreciated.
 Regards.

 Nicolas Guilhot


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]