本文介绍如何使用php正则表达式获取百度音乐排行榜top500数据,并显示在我们自己的网页中,
代码经本人调试成功,可作参考
代码如下:取百度音乐排行榜top500
百度音乐top500body{
font-size:12px;
font-family:Verdana, Arial, Helvetica, sans-serif;
}
ul{
clear:both;
padding:0;
margin:0;
list-style:none;
}
#inner{
width:960px;
margin-left:auto;
margin-right:auto;
text-align:center;
}
#tableFrame{
width:960px; /*需要修改*/
border-top:#000 1px solid;
border-left:#000 1px solid;
font-size:12px;
}
#tableFrame:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}
li{
float:left;
display: block;
width:190px; /*需要修改*/
height:41;
padding:2px;
margin:0;
border-right:#000 1px solid;
border-bottom:#000 1px solid;
line-height:16px;
color:000;
overflow:scroll;
}
/* 表格标题*/
#tableFrameTitle ul{}
#tableFrameTitle ul li{
background:gray;
text-align:center;
color:#fff;
}
/* 表格内容*/
#tableCase ul{}
#tableCase ul li{}
/* 单个表格特定样式*/
.tableCaseThree{color:#329A02;}
.tableCaseFive{color:#f00;}
.tableCaseSeven{color:#f00;}
- 排名
- 歌名
- 排名变化趋势
- 红雨
- RedRain
$contents=file_get_contents("http://music.baidu.com/top/dayhot");
$pattern="{]+song-title[^>]+>}U";
preg_match_all($pattern,$contents,$out,PREG_PATTERN_ORDER);
$pattern1="{[1-9][0-9]{0,2}.*}U";
preg_match_all($pattern1,$contents,$out1,PREG_PATTERN_ORDER);
$c=0;
for($i=0;$i<500;$i++){
if($c==5){
$c=1;
?>
}else{
$c++;
}
$get=$out[1][$i];
$get1=$out[2][$i];
$get2=$out1[1][$i];
echo "
".iconv("utf-8","gb2312",($i+1).". ".$get1." ")."";}
?>
本文由PHP中文网提供,
文章地址:http://www.php.cn/php-weizijiaocheng-377134.html
学编程就来PHP中文网 www.php.cn