Php, script et astuces

ilune_fr > Informatique > Php, script et astuces

Php Remove Special Chars

    function removeSpecialChars($str)
    {
        $str = strip_tags($str);
        $search = array ('@é|è|ê|ë|Ê|Ë@i','@à|â|ä|Â|Ä@i','@î|ï|Î|Ï@i','@û|ù|ü|Û|Ü@i','@ô|ö|Ô|Ö@i','@ç@i','@ @i','@[^a-zA-Z0-9_-]@');
        $replace = array ('e','a','i','u','o','c',' ',' ');
        $str = preg_replace($search, $replace, $str);
        return $str;
    }

Php Url Encode Array

// Two Functions for this:
    function getUrlEncodeArray($array,$baseName) { 
       $res = array();
        $this->setUrlEncodeArray($array, $baseName, $res);
        return implode('&', $res);
    }
    function setUrlEncodeArray($array,$baseName,&$res) {
        foreach($array as $key=>$value) {
            $currentBaseName = $baseName;
            if (is_numeric($key)) {
                $currentBaseName.='[]';
            } else {
                $currentBaseName.='['.$key.']';
            }
            if (is_array($value)) {
                setUrlEncodeArray($value, $currentBaseName, $res);
            } else {
                $res[]=$currentBaseName.'='.urlencode($value);
            }
        }
    }