This article describes how to use PHP regular expressions to get Baidu Music leaderboard TOP500 data, and display it in our own web page,
Code through my debugging success, can be used as a reference
The code is as follows:
Take Baidu music rankings top500 <title> Baidu Music Top500</title><style>body{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;/* Need to modify */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;/* Need to modify */height:41;padding:2px;margin:0;border-right: #000 1px solid; Border-bottom: #000 1px solid;line-height:16px;color:000;overflow:scroll;} /* Table header */#tableFrameTitle ul{} #tableFrameTitle ul Li{background:gray; Text-align:center;color: #fff;} /* Table contents */#tableCase ul{} #tableCase ul li{}/* single table-specific style */.tablecasethree{color: #329A02;}. Tablecasefive{color: #f00;}. Tablecaseseven{color: #f00;} </style><p id=inner><p id= "TableFrame" > <p id= "Tableframetitle" > <ul> & Lt;li> rankings </li> <li> song names </li> <li> ranking trends </li> <li> Red Rain < /li> <li>RedRain</li> </ul> </p> <p id= "Tablecase" ><ul>< ? php$contents=file_get_contents ("Http://music.baidu.com/top/dayhot"); $pattern = "{<[^>]+song-title[^>]+ ><a href=\ "(. *) \" Title=\ "(. *) \" >}u ";p reg_match_all ($pattern, $contents, $out, Preg_pattern_order); $ Pattern1= "{[1-9][0-9]{0,2}.*<i class=\" (. *) \ "></i>}u";p Reg_match_all ($pattern 1, $contents, $out 1,preg _pattern_order); $c =0;for ($i =0; $i <500; $i + +) {if ($c ==5) {$c = 1;? ></ul><ul><?php}else{$c + +;} $get = $out [1][$i]; $get 1= $out [2][$i]; $get 2= $out 1[1][$i];echo "<li>" Iconv ("Utf-8", "gb2312", ($i + 1). ". <a href= ' http://music.baidu.com$get ' target= ' _blank ' >. $get 1. " </a> "). </li> ";}? ></ul></p></p></p>
This article is provided by topic.alibabacloud.com,
Article Address: http://www.php.cn/php-weizijiaocheng-377134.html
Learn programming to topic.alibabacloud.com www.php.cn