<?PHP define('ROOT_PATH', './'); set_time_limit(0);
$pic_dir = ROOT_PATH.'xuxule_pic/'; $dbusername="fuckmingliang"; //用户名 $dbpass="fuckmingliang"; //密码 $dbname="fuck"; //数据库 $dbhost="localhost"; mysql_connect($dbhost,$dbusername,$dbpass); mysql_select_db($dbname);
#save special picture #此处要注意。保存图片必须设置来源。否则不能下载。 function sava_pic($filename='',$str='') { global $pic_dir; $server = 'www.xuxule.com'; $host = 'www.xuxule.com'; $port = 80; $target = "/".$filename; $referer = 'http://'.$host.$target; // Referer $File = fsockopen($server, $port, $errno, $errstr, 30); if (!$File) { echo "$errstr ($errno)<br />\n"; return ''; } else { $out = "GET $target HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Referer: $referer\r\n"; $out .= "Connection: Close\r\n\r\n";
fputs($File, $out);
$makeFile = $buffer = ""; while ($buffer = fread($File,4096)) { $makeFile = $makeFile.$buffer; } fclose($File);
preg_match("/Content-Length: (\d+)(.*)/s",$makeFile,$files); $files[2] = ltrim($files[2]); $pic_name = time()."_".$str.".jpg"; $Filename = $pic_dir.$pic_name;
$fp = fopen ($Filename,'w+'); fwrite($fp,$files[2]); fclose($fp);
return $pic_name; }
}
$SQL = " SELECT * FROM xl_special where date='' ORDER BY specialID DESC ";//05-0248 $Result = mysql_query($SQL); while ( $Row = mysql_fetch_array($Result) ) {
$url = "http://www.xuxule.com/cd.asp?cdID=".$Row['str']; $File = @file_Get_contents($url); if ( $File ) {
#save picture preg_match("/width=\"70\"(.*)border=1/s",$File,$pic2); preg_match("/href=(.{1,110}) target=_blank/",$pic2[1],$pic); $pic = sava_pic($pic[1],$Row['str']);
preg_match("/专辑介绍(.*)<td> <\/td>/s",$File,$description2);#description preg_match("/<TD>(.*)<\/TD>/s",$description2[1],$description);#description
preg_match("/出版年月(.*)<TD height=\"20\">&/s",$File,$date3);#date $st = preg_match("/:(.*)<TD height=\"20/s",$date3[1],$date2);#date if ( $st == 1 ) { preg_match("/(.*)<\/TD>/s",$date2[1],$date);#date $date[1] = trim($date[1]); } else { preg_match("/:(.*)<\/TD>/s",$date3[1],$datex);#date $date[1] = trim($datex[1]);
}
preg_match("/发行公司:(.{1,100})<\/TD>/",$File,$company);#company preg_match("/专辑类别:(.{1,100})<\/TD>/",$File,$language);#language
preg_match("/专辑曲目(.*)b_back/s",$File,$music2);#music num preg_match_all("/&songNo=(\d+) class=c>(.{1,100})<\/a>/",$music2[1],$music);#music num preg_match_all("/class=nolyric>(.{1,100})<\/span>/",$music2[1],$music_no);#music num
for ( $i=0;$i<count($music[1]);$i++) { $SQL = " INSERT INTO xl_lyric SET Name='".addslashes(trim($music[2][$i]))."',specialID='$Row[specialID]',specialName='".addslashes($Row[specialName])."',songerName='".addslashes($Row[songerName])."',songerID='$Row[songerID]',createDate='".time()."' "; mysql_query($SQL); $lyricID = $DB->_GetInsertID();
$lyricFile = @file_Get_contents("http://www.xuxule.com/lyric.asp?cdID=$Row[str]&songNo=".$music[1][$i]); if ( $lyricFile ) { preg_match("/width=500>(.*)<td height=\"30/s",$lyricFile,$lyric3);#lyric preg_match("/align=left>(.*)<\/tbody>/s",$lyric3[1],$lyric2);#lyric preg_match("/(.*)<\/tr>/s",$lyric2[1],$lyric);#lyric $lyric[1] = str_replace("</td>","",$lyric[1]); $SQL = " UPDATE xl_lyric SET lyric='".addslashes(trim($lyric[1]))."' WHERE lyricID='$lyricID' "; mysql_query($SQL); } }
for ( $j=0;$j<count($music_no[1]);$j++) { $SQL = " INSERT INTO xl_lyric SET Name='".addslashes(trim($music_no[1][$j]))."',specialID='$Row[specialID]',specialName='".addslashes($Row[specialName])."',songerName='".addslashes($Row[songerName])."',songerID='$Row[songerID]',createDate='".time()."' "; mysql_query($SQL); }
#insert into SQL $SQL = " UPDATE xl_special SET picture='$pic', description='".addslashes($description[1])."', company='".addslashes(trim($company[1]))."', date='".addslashes(trim($date[1]))."', language='".addslashes(trim($language[1]))."'
WHERE specialID='$Row[specialID]' "; mysql_query($SQL);
echo $SQL."<BR><bR>"; } }
?>
(出处:CodeFans转载) |