3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php require_once 'Services/Soundcloud.php'; /* * function to get via cUrl * From lastRSS 0.9.1 by Vojtech Semecky, webmaster @ webdot . cz * See http://lastrss.webdot.cz/ */ function curlGet($URL) { $ch = curl_init(); $timeout = 3; curl_setopt( $ch , CURLOPT_URL , $URL ); curl_setopt( $ch , CURLOPT_RETURNTRANSFER , 1 ); curl_setopt( $ch , CURLOPT_CONNECTTIMEOUT , $timeout ); /* if you want to force to ipv6, uncomment the following line */ //curl_setopt( $ch , CURLOPT_IPRESOLVE , 'CURLOPT_IPRESOLVE_V6'); $tmp = curl_exec( $ch ); curl_close( $ch ); return $tmp; } /* * function to use cUrl to get the headers of the file */ function get_location($url) { $my_ch = curl_init(); curl_setopt($my_ch, CURLOPT_URL,$url); curl_setopt($my_ch, CURLOPT_HEADER, true); curl_setopt($my_ch, CURLOPT_NOBODY, true); curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($my_ch, CURLOPT_TIMEOUT, 10); $r = curl_exec($my_ch); foreach(explode("\n", $r) as $header) { if(strpos($header, 'Location: ') === 0) { return trim(substr($header,10)); } } return ''; } function get_size($url) { $my_ch = curl_init(); curl_setopt($my_ch, CURLOPT_URL,$url); curl_setopt($my_ch, CURLOPT_HEADER, true); curl_setopt($my_ch, CURLOPT_NOBODY, true); curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($my_ch, CURLOPT_TIMEOUT, 10); $r = curl_exec($my_ch); foreach(explode("\n", $r) as $header) { if(strpos($header, 'Content-Length:') === 0) { return trim(substr($header,16)); } } return ''; } function get_description($url) { $fullpage = curlGet($url); $dom = new DOMDocument(); @$dom->loadHTML($fullpage); $xpath = new DOMXPath($dom); $tags = $xpath->query('//div[@class="info-description-body"]'); foreach ($tags as $tag) { $my_description .= (trim($tag->nodeValue)); } return utf8_decode($my_description); } // create a client object with your app credentials $client = new Services_Soundcloud( '6813c5d125013568ef986b73e4ba265c', '2eb6f212de6f4963c3873f8afdf517e9'); // a permalink to a track $track_url = 'http://soundcloud.com/forss/voca-nomen-tuum'; if($_GET['url']){ $track_url = $_GET['url']; } $url='http://api.soundcloud.com/resolve.json?url='.$track_url.'&client_id=6813c5d125013568ef986b73e4ba265c'; $headers=get_headers($url,1); $location=$headers['Location']; // resolve track URL into track resource //$track = json_decode($client->get('resolve', array('url' => $track_url))); /* now that we have the track id, we can get a list of comments, for example foreach (json_decode($client->get('tracks/' . $track->id . 'comments')) as $c) print 'Someone said: ' . $c->body . ' at ' . $c->timestamp . "\n"; try { $track = $soundcloud->download($track->id); } catch (Services_Soundcloud_Invalid_Http_Response_Code_Exception $e) { exit($e->getMessage()); } file_put_contents("files/download.mp3",$track); echo "<a href='files/download.mp3'>download</a>";*/ function modify_url($mod, $url = FALSE){ // If $url wasn't passed in, use the current url if($url == FALSE){ $scheme = $_SERVER['SERVER_PORT'] == 80 ? 'http' : 'https'; $url = $scheme.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; } // Parse the url into pieces $url_array = parse_url($url); // The original URL had a query string, modify it. if(!empty($url_array['query'])){ parse_str($url_array['query'], $query_array); foreach ($mod as $key => $value) { if(!empty($query_array[$key])){ $query_array[$key] = $value; } } } // The original URL didn't have a query string, add it. else{ $query_array = $mod; } return $url_array['scheme'].'://'.$url_array['host'].'/'.$url_array['path'].'?'.http_build_query($query_array); } $location = modify_url(array('client_id' => '6813c5d125013568ef986b73e4ba265c'), $location); $location=str_replace("//tracks","/tracks",$location); $loginUrl = $location; $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$loginUrl); curl_setopt($ch, CURLOPT_USERAGENT, $agent); $result=curl_exec($ch); curl_close($ch); //var_dump($result); $json = file_get_contents($location); $obj = json_decode($json, true); if(!$_GET['d']){ echo $location; echo "<br/>"; echo $obj['id']; } else { header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: public'); header('Content-type: application/force-download'); header('Content-Disposition: attachment; filename='.basename($obj["stream"]).";" ); header("Content-Transfer-Encoding: binary"); readfile("$obj['stream']"); } ?>
Output for 5.4.0 - 5.4.24
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /in/YQs0C on line 148
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /in/YQs0C on line 148
Process exited with code 255.