filter get and post values
===

I call my main page framework_ui.php in it I require auth.php where I have a filter function. 

    function filter($data)
    {
       // normalize $data because of get_magic_quotes_gpc
       $dataNeedsStripSlashes = get_magic_quotes_gpc();
       if ($dataNeedsStripSlashes) {
    	   $data = stripslashes($data);
       }
       // normalize $data because of whitespace on beginning and end
       $data = trim($data);
       // strip tags
       $data = strip_tags($data);
       // replace characters with their HTML entitites
       $data = htmlentities($data);
       // mysql escape string    
       $data = mysql_real_escape_string($data);
       return $data;
    }

and on every page with get and post variables I do a: (and call my framework.php)

    // filter GET values
    foreach ($_GET as $key => $value) {
        $get[$key] = filter($value);
    }
    // filter post
    foreach ($_POST as $key => $value) {
        $post[$key] = filter($value);
    } 

Will the function still operate properly if I make the above a function and call that instead on every page? 

    function filter_all() {
    // filter GET values
    foreach ($_GET as $key => $value) {
        $get[$key] = filter($value);
    }
    // filter post
    foreach ($_POST as $key => $value) {
        $post[$key] = filter($value);
    }
    }

I understand this is not the most secure way, however I was wondering if this sort of thing was possible and wouldn't negatively effect my code.