php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23239 preg_replace don(t work on multi-dimensional arrays
Submitted: 2003-04-16 07:58 UTC Modified: 2010-11-18 12:36 UTC
From: bibifoc23 at yahoo dot fr Assigned:
Status: Wont fix Package: PCRE related
PHP Version: 4.3.2-RC2 OS: windows & linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
46 - 7 = ?
Subscribe to this entry?
Further comment on this bug is unnecessary.
 
 [2003-04-16 07:58 UTC] bibifoc23 at yahoo dot fr
when i use p_reg_replace on multi-dimensional arrays, the utput  array is  one dimensional array and so i lost data.
i get this bug when i want replace patten with a ldap result (ldap_get_entries);

i use the latest win32 CVS (php4) and i get with php-4.2.3

<?php


# good result
$tableau = array ( "toto", "titi", "tata" );
$tableau2 = preg_replace ( '{t}', '-', $tableau );
var_dump ( $tableau2 );

echo "----------------------------------------------\n";
# wrong result
$tableau = array ( array ("toto"), array ("titi"), array ("tata") );
var_dump ( $tableau );
$tableau2 = preg_replace ( '{t}', '-', $tableau );
var_dump ( $tableau2 );


?>
the output is:

array(3) {
  [0]=>
  string(4) "-o-o"
  [1]=>
  string(4) "-i-i"
  [2]=>
  string(4) "-a-a"
}
---------------------------------------------
array(3) {
  [0]=>
  array(1) {
    [0]=>
    string(4) "toto"
  }
  [1]=>
  array(1) {
    [0]=>
    string(4) "titi"
  }
  [2]=>
  array(1) {
    [0]=>
    string(4) "tata"
  }
}
array(3) {
  [0]=>
  string(5) "Array"
  [1]=>
  string(5) "Array"
  [2]=>
  string(5) "Array"
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-04-30 03:54 UTC] bibifoc23 at yahoo dot fr
always the problem with preg_replace with multi-dimensional array with php-4.3.2
 [2003-04-30 03:58 UTC] derick@php.net
it's still not a bug but a feature request.
 [2003-04-30 04:09 UTC] bibifoc23 at yahoo dot fr
it 's not a feature request.

When i want to change string in a array, i use preg_replace. But this function destroy my array (like the result of a ldap search). So, if preg_replace is unable to perform a recursive replacement, the result should be the initial array. 

Or change the doc.

thanks
 [2010-11-18 12:36 UTC] jani@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: PCRE related -PHP Version: php-4.3.2-RC2 +PHP Version: 4.3.2-RC2 -Block user comment: N +Block user comment: Y
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 14:01:31 2024 UTC