php判断url链接是不是音乐文件
/**
* 判断链接是不是音乐文件
* @param string $url 链接地址
* @return bool 是就返回true,不是就返回false
*/
function url_is_audio($url = 'http://') {
$url_arr = parse_url($url);
$host = $url_arr['host'];
$path = $url_arr['path'];
echo $host . $path;
// 必须加上,不然路径都不正确
$url_encode = 'http://' . $host . '/' . rawurlencode($path);
// 返回类型是数组
$response_header_array = get_headers($url_encode, 1);
// var_dump($response_header_array);
// 如果文件类型是audio
if (preg_match("/audio/", $response_header_array['Content-Type'])) {
echo $response_header_array['Content-Type'];
return true;
} else {
// 不是audio
return false;
}
return true;
}