从千千静听歌词服务器获取lrc歌词示例分享
程序员文章站
2024-02-21 20:23:28
$name为输出歌曲名字复制代码 代码如下:
<?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 '很抱歉,百度都没找到'.$name.'的歌词,这歌曲也太给力了吧~!';
}
?>
$name为输出歌曲名字
复制代码 代码如下:
<?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 '很抱歉,百度都没找到'.$name.'的歌词,这歌曲也太给力了吧~!';
}
?>
上一篇: java解析sina视频