3v4l.org

run code in 300+ PHP versions simultaneously
<?php $twitter_handle = "twitter"; function buildBaseString($baseURI, $method, $params) { $r = array(); ksort($params); foreach($params as $key=>$value){ $r[] = "$key=" . rawurlencode($value); } return $method."&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $r)); } function buildAuthorizationHeader($oauth) { $r = 'Authorization: OAuth '; $values = array(); foreach($oauth as $key=>$value) $values[] = "$key=\"" . rawurlencode($value) . "\""; $r .= implode(', ', $values); return $r; } $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $oauth_access_token = "your own"; $oauth_access_token_secret = "your own"; $consumer_key = "your own"; $consumer_secret = "your own"; $oauth = array( 'oauth_consumer_key' => $consumer_key, 'oauth_nonce' => time(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0', 'screen_name' => $twitter_handle); $base_info = buildBaseString($url, 'GET', $oauth); $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret); $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true)); $oauth['oauth_signature'] = $oauth_signature; // Make Requests $header = array(buildAuthorizationHeader($oauth), 'Content-Type: application/json', 'Expect:'); $options = array( CURLOPT_HTTPHEADER => $header, //CURLOPT_POSTFIELDS => $postfields, CURLOPT_HEADER => false, CURLOPT_URL => $url . '?screen_name=' . $twitter_handle, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false); $feed = curl_init(); curl_setopt_array($feed, $options); $json = curl_exec($feed); curl_close($feed); $decode = json_decode($json, true); //getting the file content as array echo '<ul>'; foreach($decode as $tweet) { $tweet_text = $tweet["text"]; echo '<li>'; echo $tweet_text; echo '</li>'; } echo '</ul>'; $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; $reg_exHash = "/#([a-z_0-9]+)/i"; $reg_exUser = "/@([a-z_0-9]+)/i"; echo '<ul>'; foreach ($decode as $tweet) { $tweet_text = $tweet["text"]; //get the tweet // make links link to URL // http://css-tricks.com/snippets/php/find-urls-in-text-make-links/ if(preg_match($reg_exUrl, $tweet_text, $url)) { // make the urls hyper links $tweet_text = preg_replace($reg_exUrl, "<a href='{$url[0]}'>{$url[0]}</a> ", $tweet_text); } if(preg_match($reg_exHash, $tweet_text, $hash)) { // make the hash tags hyper links https://twitter.com/search?q=%23truth $tweet_text = preg_replace($reg_exHash, "<a href='https://twitter.com/search?q={$hash[0]}'>{$hash[0]}</a> ", $tweet_text); // swap out the # in the URL to make %23 $tweet_text = str_replace("/search?q=#", "/search?q=%23", $tweet_text ); } if(preg_match($reg_exUser, $tweet_text, $user)) { $tweet_text = preg_replace("/@([a-z_0-9]+)/i", "<a href='http://twitter.com/$1'>$0</a>", $tweet_text); } // display each tweet in a list item echo "<li>" . $tweet_text . "</li>"; } echo '</ul>'; ?>
Output for 7.2.6
Warning: Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' (this will throw an Error in a future version of PHP) in /in/u52fp on line 44 Warning: Use of undefined constant CURLOPT_HEADER - assumed 'CURLOPT_HEADER' (this will throw an Error in a future version of PHP) in /in/u52fp on line 46 Warning: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' (this will throw an Error in a future version of PHP) in /in/u52fp on line 47 Warning: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' (this will throw an Error in a future version of PHP) in /in/u52fp on line 48 Warning: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' (this will throw an Error in a future version of PHP) in /in/u52fp on line 49 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/u52fp:50 Stack trace: #0 {main} thrown in /in/u52fp on line 50
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20
Notice: Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /in/u52fp on line 44 Notice: Use of undefined constant CURLOPT_HEADER - assumed 'CURLOPT_HEADER' in /in/u52fp on line 46 Notice: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' in /in/u52fp on line 47 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/u52fp on line 48 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/u52fp on line 49 Fatal error: Uncaught Error: Call to undefined function curl_init() in /in/u52fp:50 Stack trace: #0 {main} thrown in /in/u52fp on line 50
Process exited with code 255.
Output for 5.1.2 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
Notice: Use of undefined constant CURLOPT_HTTPHEADER - assumed 'CURLOPT_HTTPHEADER' in /in/u52fp on line 44 Notice: Use of undefined constant CURLOPT_HEADER - assumed 'CURLOPT_HEADER' in /in/u52fp on line 46 Notice: Use of undefined constant CURLOPT_URL - assumed 'CURLOPT_URL' in /in/u52fp on line 47 Notice: Use of undefined constant CURLOPT_RETURNTRANSFER - assumed 'CURLOPT_RETURNTRANSFER' in /in/u52fp on line 48 Notice: Use of undefined constant CURLOPT_SSL_VERIFYPEER - assumed 'CURLOPT_SSL_VERIFYPEER' in /in/u52fp on line 49 Fatal error: Call to undefined function curl_init() in /in/u52fp on line 50
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.1
Fatal error: Call to undefined function hash_hmac() in /in/u52fp on line 39
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: hash_hmac() in /in/u52fp on line 39
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: hash_hmac() in /in/u52fp on line 39
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: hash_hmac() in /in/u52fp on line 39

preferences:
155.85 ms | 401 KiB | 215 Q