Phpaddslashes processing $ _ POST $ _ GET Array Function-PHP source code

Source: Internet
Author: User
Ec (2); phpaddslashes processing $ _ POST $ _ GET Array Function This Is My function equivalent to an automatic version and is useful for processing $ _ POST arrays & lt ;? Phpfunctionadd_slashes ($ an_array) {& nbsp; foreach ($ an_arrayas $ key & gt; $ value) {& nbsp; $ new_ar script ec (2); script

Php addslashes processing $ _ POST $ _ GET Array Function

This is my function equivalent to an automatic version and is useful for processing $ _ POST arrays.

Function add_slashes ($ an_array ){
Foreach ($ an_array as $ key => $ value ){
$ New_array [$ key] = addslashes ($ an_array [$ key]);
}
}
?>

Then call it:

Hi,
I use this recursive function. It processes multi-dimensional arrays.


Function as_array (& $ arr_r)
{
Foreach ($ arr_r as & $ val) is_array ($ val )? As_array ($ val): $ val = addslashes ($ val );
Unset ($ val );
}

As_array ($ _ POST );
?>

A little more complicated.

// 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 $ key1 => $ val ){
$ Tmp [$ key1] = addslashes_array ($ val );
}
Return $ tmp;
} Else {
Return addslashes ($ input_arr );
}
}

?>

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.