function get_european_union_countries_with_vat_rate() { return array( 'AT' => 20, 'BE' => 21, 'BG' => 20, 'CY' => 19, 'CZ' => 21, 'DE' => 19, 'DK' => 25, 'EE' => 20, 'ES' => 21, 'FI' => 24, 'FR' => 20, 'GB' => 20, 'GR' => 24, 'HU' => 27, 'HR' => 25, 'IE' => 23, 'IT' => 22, 'LT' => 21, 'LU' => 17, 'LV' => 21, 'MT' => 18, 'NL' => 21, 'PL' => 23, 'PT' => 23, 'RO' => 19, 'SE' => 25, 'SI' => 22, 'SK' => 20, ); }
Archive by Author: Tom
Detect Browser Language in PHP
/** * Function detects browser language. * returns two-letter language code on success, FALSE on failure, or an empty string. */ function get_browser_language() { return substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 ); }
Get currency exchange rate in PHP
/* * Functions gets currency exchange rate from rate-exchange.appspot.com server. * returns rate on success, else false */ function get_exchange_rate( $currency_from, $currency_to ) { $url = 'http://rate-exchange.appspot.com/currency?from=' . $currency_from . '&to=' . $currency_to; $exchange_rate = json_decode( file_get_contents( $url ) ); return ( isset( $exchange_rate->rate ) ) ? $exchange_rate->rate : false; }
Get user IP in PHP
/* * returns IP on success, null on error */ function get_the_ip() { $ip = null; if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; }
Get user country by IP in PHP – external server method
function get_user_country_by_ip( $ip ) { $country = file_get_contents( 'http://api.hostip.info/country.php?ip=' . $ip ); return $country; }