Use at own risk. Programs haven't been thoroughly tested.

function: extract_guitarchords

Regex function to extract guitar chords from a string Very usefull for parsing guitar tablature. Returns an array with chords.

Info

@author Kevin van Zonneveld
@version 0.9
@link http://kevin.vanzonneveld.net
@param (string) $data The haystack to search in

Example

Usage
print_r(extract_guitarchords($tabstring));

Outputs
Array(
0 => Gm
1 => E
2 => Cmaj7
)

Source Code

download source
<?php
    function extract_guitarchords($data){
        
        $pattOneChord = '([A-G](#|b){0,1})([#\(\),-12345679Mabdgijmnorsu]){0,8}';
        $patt = '(('.$pattOneChord.')(\/'.$pattOneChord.'){0,1})\s';
        $no_chords = array("en","and","end","found","god","find","dan","as");
        preg_match_all('/'.$patt.'/s',$data." ",$matc);
 
        $chords = array();
        foreach($matc[1] as $chord){
            $tmpchord=trim(str_replace(array(",",".","*"),"",$chord));
            $lower_tmpchord=strtolower($tmpchord);
            if(in_array($lower_tmpchord,$no_chords)) continue;
            $chords[] = $tmpchord;
        }
 
        return $chords;
    }
?>

Add comment

» Currently away on vacation. I can reply your message the 24th of July 2008. Please post anyway and check back then. Thank you!

for syntax highlighting

[CODE="Javascript"]
your_code_here();
[/CODE]

Replace "Javascript"
with "php", "text", etc.
code (to make sure you are not a spammer)

Comments

No comments. Be the first!