3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * TME API - code snippet. * * More info at: https://developers.tme.eu */ $token = 'b050bd709a43eecc443820c022b6774ca703ddb216b6f6765f';//'<put_your_token_here>'; $app_secret = '5656847466f0e5d08577';//<put_your_app_secret_here>'; $params = array( 'SymbolList' => array('1N4007'), 'Country' => 'PL', 'Currency' => 'PLN', 'Language' => 'PL', ); $response = api_call('Products/GetPrices', $params, $token, $app_secret, true); $result = json_decode($response, true); var_dump(PHP_VERSION); echo '<pre>'; print_r($result); echo '</pre>'; $w = stream_get_wrappers(); echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n"; echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n"; echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n"; echo 'wrappers: ', var_dump($w); //--------------------------------------------------------- function api_call($action, $params, $token, $app_secret, $show_header=false) { $api_url = 'https://api.tme.eu/' . $action . '.json'; $curl = curl_init(); // calculate HMAC-SHA1 signature $params['Token'] = $token; ksort($params); // In PHP 5.4 http_build_query() offers enc_type parameter (PHP_QUERY_RFC3986) which replaces bellow snippet. $encoded_params = str_replace( array('+', '%7E'), array('%20', '~'), http_build_query($params) ); $signature_base = 'POST' . '&' . rawurlencode($api_url) . '&' . rawurlencode($encoded_params); $api_signature = base64_encode(hash_hmac('sha1', $signature_base, $app_secret, true)); $params['ApiSignature'] = $api_signature; //-- curl_setopt($curl, CURLOPT_URL, $api_url); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params)); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_HEADER, 1); $response = curl_exec($curl); $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); if($show_header){ print_r($header); } curl_close($curl); return $body; }
Output for 7.0.0 - 7.1.0
Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/6CZEC:37 Stack trace: #0 /in/6CZEC(17): api_call('Products/GetPri...', Array, 'b050bd709a43eec...', '5656847466f0e5d...', true) #1 {main} thrown in /in/6CZEC on line 37
Process exited with code 255.
Output for hhvm-3.12.0
string(11) "5.6.99-hhvm" <pre></pre>openssl: yes http wrapper: yes https wrapper: yes wrappers: array(10) { [0]=> string(14) "compress.bzip2" [1]=> string(13) "compress.zlib" [2]=> string(4) "data" [3]=> string(4) "file" [4]=> string(4) "glob" [5]=> string(4) "http" [6]=> string(5) "https" [7]=> string(4) "phar" [8]=> string(3) "php" [9]=> string(3) "zip" } * Could not resolve host: api.tme.eu * Closing connection 0
Output for hhvm-3.10.0
string(11) "5.6.99-hhvm" <pre></pre>openssl: yes http wrapper: yes https wrapper: yes wrappers: array(9) { [0]=> string(13) "compress.zlib" [1]=> string(4) "data" [2]=> string(4) "file" [3]=> string(4) "glob" [4]=> string(4) "http" [5]=> string(5) "https" [6]=> string(4) "phar" [7]=> string(3) "php" [8]=> string(3) "zip" } * Could not resolve host: api.tme.eu * Closing connection 0
Output for 5.0.0 - 5.6.28
Fatal error: Call to undefined function curl_init() in /in/6CZEC on line 37
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: curl_init() in /in/6CZEC on line 37
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: curl_init() in /in/6CZEC on line 37
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: curl_init() in /in/6CZEC on line 37