Everyone loves Music and i’m sure that everyone has searched for a lyric of a song before. Right? Right. So why not build a lyric search for your own website? Too complicated? No way. I show you how you can build your own Music Search Engine with less than 20 lines of code – using the API of the awesome Lyricwiki.org Website. With these few lines you can search for over 680.000 Lyrics. So lets go – here is the code:
$artist = $_GET["artist"]; //get your artist $song = $_GET["song"]; //get your song $artist = str_replace(" ", "_", $artist); //Replace spaces with_ $song = str_replace(" ", "_", $song); //Replace spaces with_
<!--Now a simple HTML Form with artist and song fields --> <form action="<?php $_SERVER["PHP_SELF"];?>" method="get"> <label for="artist">Artist:</label> <input type="text" name="artist" value="<?php echo $artist;?>" id="artist" /> <label for="song">Songname:</label> <input type="text" name="song" value="<?php echo $song;?>" id="song"/> <input type="submit" value="search"/> </form>
// The important part-get the Lyric from the Lyricwiki.org API $info = file_get_contents("http://lyricwiki.org/api.php?artist=".$artist."&song=".$song."&fmt=text"); echo nl2br($info); //echo our searched lyrics
Check out the Example of this script. If you just enter an Artist and no Song name, all songs of the found Artist will be displayed! Cool stuff!
Download the Code
Grab this script and use it as you want – a backlink to kollermedia.at would be awesome of course 🙂
Music Lyric Search Engine (703 bytes, 1.428 hits)