Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[发布] 在自己的网站中加百度mp3搜索之php版

[复制链接]
hydeist 发表于 2006-1-25 18:57:11 | 显示全部楼层 |阅读模式
下面是代码,把代码存成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>
------------------------------------------------------------------------------------------------------------------------------------------
xjbl 发表于 2006-1-25 18:58:41 | 显示全部楼层
哦...
回复

使用道具 举报

zhylsy99 发表于 2006-1-25 23:39:25 | 显示全部楼层
uop
回复

使用道具 举报

MAXJAY 发表于 2006-1-25 23:42:32 | 显示全部楼层
有错误
回复

使用道具 举报

forout 发表于 2006-1-25 23:49:47 | 显示全部楼层
尚可用吗
回复

使用道具 举报

MopPP.Com 发表于 2006-1-25 23:51:57 | 显示全部楼层
有错误么?
回复

使用道具 举报

静静の听音乐 发表于 2012-6-7 10:10:33 | 显示全部楼层
能用吗?

www.kafeibbs.com
咖啡屋,缘聚咖啡小屋,邂逅浪漫爱情!
回复

使用道具 举报

zz26418264 发表于 2013-7-14 14:45:50 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-9-22 19:40 , Processed in 0.146345 second(s), 16 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表