PHP addslashes processing $_post $_get Array function

Source: Internet
Author: User
Keywords Web Programming PHP Tutorials
Tags array automatic function is_array key php process processing

PHP addslashes processing $_post $_get Array function

This is my one equivalent to the automatic version of the feature used to handle the $ _post array useful

<?php
function add_slashes ($an _array) {
foreach ($an _array as $key => $value) {
$new _array[$key] = addslashes ($an _array[$key]);
}
}
?>

Then call it:

<?php add_slashes ($_post);?>

Hey,
I use this recursive function. It handles multidimensional arrays.


<?php
Function As_array (& $arr _r)
{
foreach ($arr _r as & $val) Is_array ($val)? As_array ($val): $val =addslashes ($val);
Unset ($val);
}

As_array ($_post);
?>

More complicated.

<?php
//create array to temporarily grab variables
$input _arr = Array ();
//grabs the $_post variables and Adds slashes
foreach ($_post as $key => $input _arr) {
    if (Is_array ($input _arr)) {        
        $_post[$key] = Addslashes_ Array ($input _arr);
   }else{
        $_post[$key] = addslashes ($input _arr);
   }
   
}

Recursive Function to add slashes with posted array.
function Addslashes_array ($input _arr) {
if (Is_array ($input _arr)) {
$tmp = Array ();
foreach ($input _arr as $key 1 => $val) {
$tmp [$key 1] = Addslashes_array ($val);
}
return $tmp;
}else{
Return addslashes ($input _arr);
}
}

?>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.