本篇文章主要介紹php通過新浪樂庫搜尋介面查詢歌曲的功能,感興趣的朋友參考下,希望對大家有所協助。
具體如下:
<form name="" method="post" action=""><input name="key" type="text" /> <input name="submit" type="submit" value="搜歌" /></form><pre><?php header('meta http-equiv="content-type"content="text/html; charset=gb2312"');if( isset( $_REQUEST['submit']) && isset( $_REQUEST['key']))$key = $_REQUEST['key'];else $key = '周杰倫';$url = 'http://music.sina.com.cn/yueku/search/getRecommendXml1dot0.php?q='.urlencode($key).'&l=50&json=json';$data = file_get_contents( $url);$data = json_decode( $data);if( !count($data)) echo 'Not found';?></pre><?php foreach( $data as $one){ $music = $one->MP3URL; $music = file_get_contents( $music); $music = str_replace('iask_music_song_url="' , '', str_replace('";' , '', $music));?><p><?php echo 'ALBUM_NAME : '.$one->NAME.' MUSIC_URL : <a href='.$music.'>'.$one->NAME.'</a>'.' SINGER_NAME'.$one->SINGERCNAME;?></p><?php }?>
總結:以上就是本篇文的全部內容,希望能對大家的學習有所協助。
相關推薦:
PHP類比asp中response類的方法
PHP中如何擷取使用者IP地址
PHP的變數及日期處理案例