$name is the output song name
Copy the code code as follows:
<?php
error_reporting(0);
function ConvertUrlEncode($text)
{
$textUrl = htmlspecialchars(urlencode($text));
return $textUrl;
}
$Type=substr($name,-4);
$name1=str_replace($Type,"",$name);
$name2=str_replace("-","",$name1);
$uk=ConvertUrlEncode($name2);
$str=file_get_contents('http://music.baidu.com/search/lrc?key='.$uk);
preg_match_all('/<p id="lyricCont-0">(.*?)<//p>/is',$str, $arr);
foreach ($arr[1] as $k => $v){
}
if($v){
echo $v;
}else{
echo 'Sorry, Baidu couldn't find the lyrics for '.$name.', this song is so awesome~! ';
}
?>