3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Install this pear extention on linux by doing: $ pear channel-discover phpquery-pear.appspot.com $ pear install phpquery/phpQuery */ require('phpQuery.php'); /** * Gets the server that a player has joined * @param string $username The username of the player * @return array An array that consists of: success, title, url and errorCode */ $username = "SoL0vex" ; function getJoinedServer ($username) { $curl = curl_init("http://battlelog.battlefield.com/bf3/user/$username"); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); curl_setopt($curl, CURLOPT_TIMEOUT, 30); $doc = phpQuery::newDocument(curl_exec($curl)); phpQuery::selectDocument($doc); $li = pq('.common-playing-link a'); if (pq($li)->attr('href')) { return array('success' => true, 'title' => pq($li)->attr('title'), 'url' => 'http://battlelog.battlefield.com' . pq($li)->attr('href')); } else { return array('success' => false, 'errorCode' => 1); } curl_close($curl); } // Measure time $mtime = microtime(); $mtime = explode(' ',$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; // Get joined server $result = getJoinedServer((isset($_GET['user']) ? $_GET['user'] : 'diegorod')); if($result['success']) { echo "<a href='${result['url']}'>${result['title']}</a>"; } elseif ($result['errorCode'] === 1) { echo 'User not playing'; } // Stop measuring time $mtime = microtime(); $mtime = explode(' ',$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); // Output execution time echo '<br>This page was created in '.$totaltime.' seconds'; ?>

preferences:
35.9 ms | 402 KiB | 5 Q