下面是代码,把代码存成mp3.php,运行即可。
------------------------------------------------------------------------------------------------------------------------------------------
<?php
function getcontent($str,$start,$end)
{
if ($start==''||$end=='')
{
return;
}
$tmpstr=explode($start,$str);
$tmpstr=explode($end,$tmpstr[1]);
// $str=strstr($end,$str);
return $tmpstr[0];
}
function getmp3($str)
{
if (strstr($str,"有问题请参考<A href"))
{
?>
<table width="776" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000099">
<tr align="center" bgcolor="#FFFFCC">
<td width="496">音乐名称</td>
<td width="70">格式</td>
<td width="70">大小</td>
<td width="70">速度</td>
<td width="70">下载</td>
</tr>
<?php
$tmpstrs=explode("<td width=10px valign=top>",$str);
$c=count($tmpstrs);
for($i=1; $i<$c; $i++)
{
$tmpstr=$tmpstrs[$i];
$addr=getcontent($tmpstr,"请点击左键!来源网址: "," 请参照百度权利声明使用");//得到下载地址
$tmpstr=strstr($tmpstr," 请参照百度权利声明使用");
$name=getcontent($tmpstr,"onclick=\"return ow(this)\" >","</a>");//得到音乐名称
$tmpstr=strstr($tmpstr,"</a>");//去掉垃圾信息
$tmpstr=strstr($tmpstr," </td>");
// $tmpstr=strstr($tmpstr,"<a href=");
$tmpstr=strstr($tmpstr,"</td>");
$tmpstr=strstr($tmpstr," </td>");
$tmpstr=strstr($tmpstr,"<td>");
$size=getcontent($tmpstr,"<td>","</td>");//得到文件大小
$tmpstr=strstr($tmpstr,"</td>");
$tmpstr=strstr($tmpstr,"<td>");
$ext=getcontent($tmpstr,"<td>","</td>");//得到文件格式
$tmpstr=strstr($tmpstr,"</td>");
$speed=getcontent($tmpstr,"http://img.baidu.com/img/mp3/d",".gif");//得到链接速度
?>
<tr align="center" bgcolor="#F7FFF4">
<td><?php echo $name ?></td>
<td><?php echo $ext ?></td>
<td><?php echo $size ?></td>
<td><?php echo $speed ?></td>
<td><a href="<?php echo $addr ?>">点击下载</td>
</tr>
<?php
}
echo "</table>";
// echo $str;
}
else
{
echo "对不起,没有搜索到您要找的音乐";
}
}
function table()
{
?>
<br><br><br><br><br><br>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">在自己的网站中用百度MP3搜索</td>
</tr>
<tr>
<td><form name="form1" method="post" action="mp3.php?action=search">
音乐搜索:
<input name="word" type="text" id="word" size="50">
<input type="submit" name="Submit" value="搜索">
</form></td>
</tr>
</table>
<?php
}
function search()
{
?>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center">在自己的网站中用百度MP3搜索</td>
</tr>
<tr>
<td><form name="form1" method="post" action="mp3.php?action=search">
音乐搜索:
<input name="word" type="text" id="word" size="50">
<input type="submit" name="Submit" value="搜索">
</form></td>
</tr>
</table>
<?php
$url="http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=".$_POST["word"]."&lm=-1";//百度mp3搜索网址
$html=file_get_contents($url);//抓网页
getmp3($html);//分析并输出音乐信息
//echo $html;
}
?>
<html>
<head>
<title>自己的百度mp3搜索php版</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
a:link {color: #004080;text-decoration:none;}
a:visited {color: #004080;text-decoration:none;}
a:hover{color: #FF0000;text-decoration:underline;}
a:active {color: #004080;text-decoration:none;}
select,p,td{font-size:9pt;line-height:150%;}
input,textarea{font-size:9pt;font-family:宋体}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">
<?php
if (isset($_GET["action"]))
{
if ($_GET["action"]="search")
{
search();
}
else
{
table();
}
}
else
{
table();
}
?>
</body>
</html>
------------------------------------------------------------------------------------------------------------------------------------------
完 |