<?PHP
/*
たとえばこちらのアルバム情報を取得したいとします
https://open.spotify.com/album/2VX9rp6NAC19TQN4IgkmYu?si=xBgO8B_lTA6tFDLOgQCAkA
*/
$inputURL = 'https://open.spotify.com/album/2VX9rp6NAC19TQN4IgkmYu?si=xBgO8B_lTA6tFDLOgQCAkA';
if (substr($inputURL, strlen($inputURL)-1) === '/') {
$inputURL = substr($inputURL, 0, strlen($inputURL)-1);
}
$arr = explode('/', $inputURL);
$type = $arr[3];
$target = urlencode($arr[4]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.spotify.com/v1/search?q=".$target."&type=".$type."");
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$data = curl_exec($ch);
curl_close($ch);
echo '<pre>'.$data.'</pre>';
?>