尝试了很多组合,但没有任何作用。
$json = file_get_contents("http://www.theaudiodb.com/api/v1/json/58424d43204d6564696120/search.php?s=$artist");
如果$artist
变量包含不适合在URL中使用的字符(如空格,标点符号等),我唯一能想到的就是“工作”。
PHP有一个函数可以使字符串安全地用于URL~urlencode()
...
$artist = 'Pink Floyd'; // spaces should be encoded as "%20" or "+"
$json = file_get_contents(sprintf(
'http://www.theaudiodb.com/api/v1/json/58424d43204d6564696120/search.php?s=%s',
urlencode($artist)));