Recommended:

  • phpclasses.org
  • jsclasses.org
  • jsmag.com
  • siteapps.com
  • View our reviews on Hot Scripts
  • JS Tutorial
  • scripts.com
  • securesignup.com




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 http://pargitaru.id.lv/api/ 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

<?php
//$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 = "http://pargitaru.id.lv/api/";
    if($special)
    {
        $url .= "?request=special";
    }
    else
    {
        $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);
    curl_close($curl);
    
    //decoding json structure into array
    return json_decode($curlData, true);
}

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

You may also be interested in:

Powered by BlogAlike.com

blog comments powered by Disqus