buraisu Posted November 8, 2006 Share Posted November 8, 2006 Hi there. I am trying to whip something up for the store I work at.Basically what needs to happen is a customers driver liscence will be scanned and the data stored on the card needs to be automatically filled into a database.This is the data scanned from a card(edited for privacy.)%BCSURREY^LASTNAME, FIRSTNAME$MIDDLENAME^12345 154 ST$SURREY BC V6R 4K8^?;6360288190379=080919880720=?%0AV3R4J8 M173 89BRNBRN MW$'X$51 ?I have it so that when the card is swiped the info is sent in a string variable to my php script.So I have $_POST['cardinfo'] which has all that data in it.now what I dont know how to do is get the data from in that variable seperated into seperate variables (or into arrays) for the first name, last name, address, etc...Anyone have an idea how I could do this? Quote Link to comment Share on other sites More sharing options...
bqallover Posted November 8, 2006 Share Posted November 8, 2006 You'd use regular expressions. For example to get the name you'd have something like [code]if( eregi( '\^([a-z]+), ([a-z]+)\$([a-z]+)\^', $_POST['cardinfo'], $regs ) ){ $lastname = $regs[1]; $firstname = $regs[2]; $middlename = $regs[3];}[/code]I can't determine an address from your scanned code though? Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 8, 2006 Share Posted November 8, 2006 Something like this:[code]$array = preg_split('/%\w+\^|, |\$\'?|\^|\?\s*(;|%)|=|\s{5,}|\s+\?/', $string);print_r($array);[/code]gives me this array()[code]Array( [0] => [1] => LASTNAME [2] => FIRSTNAME [3] => MIDDLENAME [4] => 12345 154 ST [5] => SURREY BC V6R 4K8 [6] => [7] => 6360288190379 [8] => 080919880720 [9] => [10] => 0AV3R4J8 [11] => M173 89BRNBRN [12] => MW [13] => X [14] => 51 [15] => )[/code] Quote Link to comment Share on other sites More sharing options...
buraisu Posted November 9, 2006 Author Share Posted November 9, 2006 omg. thanks.I dont know regular expressions yet.I should learn them! Quote Link to comment Share on other sites More sharing options...
buraisu Posted November 9, 2006 Author Share Posted November 9, 2006 Does anyone know how I would be able to break this [5] => SURREY BC V6R 4K8into 3 partsSurrey, BC, and the postal code? Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 9, 2006 Share Posted November 9, 2006 [code=php:0]list($surrey, $bc, $postal) = preg_split('/\s+/', $array[5], 3);[/code] Quote Link to comment Share on other sites More sharing options...
buraisu Posted November 12, 2006 Author Share Posted November 12, 2006 Ok, regex is beyond my php scope.but hopefully somone else can help me some more.The above code worked perfect for the one scanned drivers liscence, but when I tried others I got some errors.Here are some more examples[quote]%BCSURREY^DESMOCKIS, JOHN$WILLIAM^12549 164 ST$SURREY BC V6R 4J9^?;6360288190379=080919880720=?%0AV3R4J8 M173 89BRNBRN MW$'X$51 ?%BCPLURAL RIVER^BOND, BRYCE ANDREW^7431 NUTA CR$PLURAL RIVER BC V9A 535^?;6360287655941=070519880901=?%0AV8A5J5 M191 82BRNBRN 'R++S4933 ?%BCABBOTSFORD^KLINGON, LUCY JORDAN^39994 EPSON PL$ABBOTSFORD BC V3E 1L4^?;6360287906496=100819880801=?%0AV3G1J4 M168 54BRNHAZ U8()R"690 ?[/quote]I think the problem is that it was never taken into consideration that there are town with more than one work, and people may have first/last/middle names that also have more than one word.thanks for any help Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 12, 2006 Share Posted November 12, 2006 BC is the Province right (sorry I'm in the U.S. don't know Canadanian Geography all that well).Are province abbreviations all two letters? How many are there? Maybe you could use an array of Provincial abbreviations to search the City Province Zip line of the array for the Province. Every thing on the left side of the Province is City and everything on the right side is zip.Are all Canadian driver's licenses the same? They ALL store the same info the same way? Quote Link to comment Share on other sites More sharing options...
Nicklas Posted November 12, 2006 Share Posted November 12, 2006 This should do the trick! ;)[code=php:0]preg_match_all('/\w+/', $string, $matches);print_r($array);[/code]Gives me this:[code]Array( [0] => BCABBOTSFORD [1] => KLINGON [2] => LUCY [3] => JORDAN [4] => 39994 [5] => EPSON [6] => PL [7] => ABBOTSFORD [8] => BC [9] => V3E [10] => 1L4 [11] => 6360287906496 [12] => 100819880801 [13] => 0AV3G1J4 [14] => M168 [15] => 54BRNHAZ [16] => U8 [17] => R [18] => 690)[/code] Quote Link to comment Share on other sites More sharing options...
buraisu Posted November 12, 2006 Author Share Posted November 12, 2006 [quote author=doni49 link=topic=114332.msg466877#msg466877 date=1163346093]BC is the Province right (sorry I'm in the U.S. don't know Canadanian Geography all that well).Are province abbreviations all two letters? How many are there? Maybe you could use an array of Provincial abbreviations to search the City Province Zip line of the array for the Province. Every thing on the left side of the Province is City and everything on the right side is zip.Are all Canadian driver's licenses the same? They ALL store the same info the same way? [/quote]I only need to worry about BC drivers licenses.As the other provinces do not all even have magnetci strips on them, and the data is stored differently on the ones that do. Quote Link to comment Share on other sites More sharing options...
buraisu Posted November 12, 2006 Author Share Posted November 12, 2006 [quote author=Nicklas link=topic=114332.msg466968#msg466968 date=1163364629]This should do the trick! ;)[code=php:0]preg_match_all('/\w+/', $string, $matches);print_r($array);[/code]Gives me this:[code]Array( [0] => BCABBOTSFORD [1] => KLINGON [2] => LUCY [3] => JORDAN [4] => 39994 [5] => EPSON [6] => PL [7] => ABBOTSFORD [8] => BC [9] => V3E [10] => 1L4 [11] => 6360287906496 [12] => 100819880801 [13] => 0AV3G1J4 [14] => M168 [15] => 54BRNHAZ [16] => U8 [17] => R [18] => 690)[/code][/quote]Thanks for the help, but that isnt quite what I need.I need to have the addresses more like this[4] => 39994 EPSON PL[5] => ABBOTSFORD[6] => BC[7] => V3E 1L4The addresses are listed like this39994 EPSON PL$ABBOTSFORD BC V3E 1L4^Splitting things with spaces wont work, becuase there are sometimes streets/cities with more than one word.maybe you could store everything before the $ in one array, and then everything between the $ and the BC in one array. and then everything after the BC and before the ^ in another one.Can that be done?Thanks alot for any help Quote Link to comment 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.