• View our reviews on Hot Scripts
  • JS Tutorial

Recent Comments

Powered by Disqus

Back to articles

Get all guitar chord variations

Here is a function that can get all guitar chord variations using chord name. It uses API, which can give chord information based on chord names, modifications like major, minor, etc, or any string and fret combination.

This function takes chord name as a parameter, you can specify chord modification - minor, major, sus, dim, etc(optional). And you can specify if chord you are looking for is special chord.

For possible chord modification values and more information look at Guitar chord API documentation

//$chord_name - name of the chord case insensitive
//$modf - chord modification like minor, major, etc
//$special - bool if chord is special or not
function get_chord($chord_name, $modf = "", $special = false)
    //building url
    $url = "";
        $url .= "?request=special";
        $url .= "?request=chords";
    $url .= "&chord=".$chord_name;
    if(!$special && trim($modf) != "")
        $url .= "&modf=".$modf;
    $url .= "&type=json";

    //curl request
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlData = curl_exec($curl);
    //decoding json structure into array
    return json_decode($curlData, true);

$arr = get_chord("C", "major");
echo "<pre>";
echo "</pre>";

You may also be interested in:

Powered by

blog comments powered by Disqus