PHP Classes

File: voidrslashes.php

Recommend this page to a friend!
  Classes of Armand Pasteau   Add and strip slashes recursively (updated)   voidrslashes.php   Download  
File: voidrslashes.php
Role: Class source
Content type: text/plain
Description: adds/strips slashes recursively
Class: Add and strip slashes recursively (updated)
Adds and strips slashes from strings recursively
Author: By
Last change: Bug fixed: difference between *nix and windows implementation of array_merge() cause that, this class was stripping out arrays in array under *nix. Now all is ok!
Date: 21 years ago
Size: 910 bytes
 

Contents

Class file image Download
<?php

/**
* This simple class adds/strips slashes recursively
*
* It can be easily extracted from class into the global functions
*/
class voidrslashes
{
    function
add($array)
    {
       
$ret = array();
        foreach (
$array as $key => $value)
        {
            if (
is_array($value))
            {
               
$ret[$key] = array_merge($ret[$key], $this->add($value));
                continue;
            }
           
$ret[$key] = addslashes($value);
        }
        return
$ret;
    }

    function
strip($array)
    {
       
$ret = array();
        foreach (
$array as $key => $value)
        {
            if (
is_array($value))
            {
               
$ret[$key] = array_merge($ret[$key], $this->strip($value));
                continue;
            }
           
$ret[$key] = stripslashes($value);
        }
        return
$ret;
    }
}
?>