alpineapple Posted January 6, 2009 Share Posted January 6, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/139626-isolating-single-or-double-digit-fret-numbers-in-guitar-tabs/ Share on other sites More sharing options...
RussellReal Posted January 6, 2009 Share Posted January 6, 2009 regex give me 2 minutes Quote Link to comment https://forums.phpfreaks.com/topic/139626-isolating-single-or-double-digit-fret-numbers-in-guitar-tabs/#findComment-730612 Share on other sites More sharing options...
RussellReal Posted January 6, 2009 Share Posted January 6, 2009 <?php $Ehighnote = array('E','F','F#','G','G#','A','A#','B','C','C#','D','D#','E'); echo preg_replace("/(\d+?)/e",'\$Ehighnote["\1"]',"-1--1--3-3--3-3-3-3-3--"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/139626-isolating-single-or-double-digit-fret-numbers-in-guitar-tabs/#findComment-730620 Share on other sites More sharing options...
sasa Posted January 6, 2009 Share Posted January 6, 2009 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/139626-isolating-single-or-double-digit-fret-numbers-in-guitar-tabs/#findComment-730650 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.