Home >Backend Development >PHP Tutorial >How to implement simple song search in PHP_php skills
The example in this article describes how to implement a simple song search in PHP. Share it with everyone for your reference. The specific implementation method is as follows:
<form name="" method="post" action=""> <input name="key" type="text" /> <input name="submit" type="submit" value="搜歌" /> </form> <pre class="brush:php;toolbar:false"> <?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'; ?><?php foreach( $data as $one){ $music = $one->MP3URL; $music = file_get_contents( $music); $music = str_replace('iask_music_song_url="' , '', str_replace('";' , '', $music)); ?>
I hope this article will be helpful to everyone’s PHP programming design.