<?php

    class parse{

        public static function countryCode(){
            
            if( !function_exists('geoip_country_code_by_name') ){
                $geo_api = @file_get_contents("http://api.ipinfodb.com/v3/ip-country/?key=4bacea0de9b98d10c03b810512c625689688dbba38243ac664b5062c45bd736a&ip=" . $_SERVER['REMOTE_ADDR']); 
                list($status, $wtf, $ip, $code, $country) =  @explode(';', $geo_api);
            } else {
                $code = @geoip_country_code_by_name($_SERVER['REMOTE_ADDR']);
            }

            if(empty($code) or $code=='-') return 'PL';
             
                return $code;
        }
        /**
         * Parse Query String
         * @return array( 'key' => val )
         */
        public static function query_string( $query_string = false ){
            
            $arr = array();
            $query_string = $query_string ? $query_string : $_SERVER['QUERY_STRING'];
            
            // No Params
            if( empty( $query_string) ) return $arr;
            
            
            // Multiple Params
            if( stristr( $query_string , '&' ) ){
                
                
                $groups = explode( '&' , $query_string );
                
                foreach( $groups as $param ){
                    
                    if( stristr( $param , '=' ) ){
                        
                        list( $key , $value ) = explode( '=' , $param );
                        $arr[$key] = $value;
                        
                    }
                    
                }
                
            // One Param
            } else {
                
                if( stristr( $query_string , '=' ) ){
                    
                    list( $key , $value ) = explode( '=' , $query_string );
                    $arr[$key] = $value;
                    
                }    
                
            }
            
                return $arr;
            
        }
    }

?>