Edit report at http://bugs.php.net/bug.php?id=52500&edit=1

 ID:                 52500
 User updated by:    jason dot gerfen at gmail dot com
 Reported by:        jason dot gerfen at gmail dot com
 Summary:            Using array_map, strip tags & nested $_POST array
 Status:             Bogus
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   Ubuntu 10
 PHP Version:        5.2.14
 Block user comment: N

 New Comment:

Thanks. I suppose I thought array_map should work recursively.


Previous Comments:
------------------------------------------------------------------------
[2010-07-31 10:59:56] johan...@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

this call strip_tags in a way similar to this:





strip_tags(array('level-2-1', $var1,

                                  'level-2-2', $var2,

                                  'level-2-3', $var3));



which gives an unexpected result.



what you need is wrapper handling the recusrion similar to



function strip_tags_recursive($data) {

     if (is_array($data)) {

         return array_map('strip_tags_recursive', $data);

     } else {

         return strip_tags($data);

     }

}



$myget = strip_tags_recursive($_GET);



While all this isuntested but shouldgive you the idea.

------------------------------------------------------------------------
[2010-07-30 15:33:55] jason dot gerfen at gmail dot com

Description:
------------
When using a combination of array_map() & strip_tags to create a
localized copy of the $_POST superglobal array I am experiencing
problems if $_POST contains a nested array.



It seems to discard any secondary iteration of said nested array.

Test script:
---------------
$_POST = array('level-1-1', $var1,

               'level-1-2', $var2,

               'level-1-3', $var3,

               'level-1-4', array('level-2-1', $var1,

                                  'level-2-2', $var2,

                                  'level-2-3', $var3),

               'level-1-5', $var5);



$post = array_map(strip_tags, $_POST);



echo '<pre>'; print_r($post); echo '</pre>';



/* I am left with this?

level-1-1 => $var1

level-1-2 => $var2

level-1-3 => $var3

level-1-5 => $var5

*/

Expected result:
----------------
I expected a complete copy of the nested superglobal $_POST.

Actual result:
--------------
Any nested array information is getting stripped out.


------------------------------------------------------------------------



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

Reply via email to