Jump to content

Recommended Posts

This seems like an incredibly simple task/stupid question, but I have searched and I cant find a simple way to do this. I want to take numbers from guitar tabs (ranging from 0 to around 18) and convert them to the letter form of the note that they are.

Im having trouble with taking the numbers out of the string (for example, one string might be "|----2----4-1-10-10-12-10---3|----2h3p0--|"). Right now Im using this code:

 

$Ehighfret = array('-0-','-1-','-2-','-3-','-4-','-5-','-6-','-7-','-8-','-9-','-10-','-11-','-12-');
$Ehighnote = array('-E-','-F-','-F#','-G-','-G#','-A-','-A#','-B-','-C-','-C#-','--D-','-D#-','--E-');
$Ehigh = str_replace($Ehighfret,$Ehighnote,$ar[0]);
echo $Ehigh . "<br />";

 

It needed to be '-1-'  instead of just '1' (etc) because otherwise the 10s 11s and 12s wouldnt work.

the problem with this, however, is that not all numbers have a '-' on both sides of them(ex "--3|"). Also, when a fret number is repeated (example "---3-3-3-3-3-3--") it only converts every other number (the output would be "---G-3-G-3-G-3--").

 

So, whats the best and quickest way for the script to find each fret number and put that into an array (or some other way to isolate each number)?

 

Thanks!

or

<?php
$Ehighnote = array('E','F','F#','G','G#','A','A#','B','C','C#','D','D#','E');
$test = '|----2----4-1-10-10-12-10---3|----2h3p0--|';
echo preg_replace("/(?<=-|\|)(\d+)(?=-|\|)/e",'\$Ehighnote["\1"]', $test);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.