本文实例讲述了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));
?>
<div><?php echo 'album_name : '.$one->name.' music_url : <a href='.$music.'>'.$one->name.'</a>'.' singer_name'.$one->singercname;?></div>
<?php }
?>
希望本文所述对大家的php程序设计有所帮助。