php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52500 Using array_map, strip tags & nested $_POST array
Submitted: 2010-07-30 15:33 UTC Modified: 2010-07-31 18:17 UTC
From: jason dot gerfen at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.14 OS: Ubuntu 10
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: jason dot gerfen at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-30 15:33 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-31 10:59 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-07-31 10:59 UTC] johannes@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-31 18:17 UTC] jason dot gerfen at gmail dot com
Thanks. I suppose I thought array_map should work recursively.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 07 04:01:27 2025 UTC