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:

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

Example

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)

  1. I was looking for an example of how to implement the api at lyricwiki and this looks great except that when I try to search a song name nothing comes up. Was there an update on the lyricwiki api which disallows this implementation?

    Also I tried searching for a recent artist and nothing comes up but when you search on the lyricwiki website it comes up. I don’t really know why this is happening.

    If you could help me with implementing the api it would be greatly appreciated.

    Thank you,
    James

  2. Hi James,
    it still does work.

    Just try Mariah Carey and click search.
    Or try Mariah Carey and Alone in Love

    If you search for a Song you always have to enter an artist & the song name.

  3. Hi!
    Ich habe dieses Script für meine Webseite benutzt. Leider habe ich festgestellt, dass sie nicht mehr funktioniert.
    Anscheinend hat Wiki änderungen vorgenommen.
    Könntest Du mir bitte sagen was ich jetzt ändern muss?
    Ich habe sehr wenig erfahrung mit Scripting! (Newbee :()
    Ich danke Dir im voraus.

Sag mir was du denkst

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>