Jump to content

Extracting Drivers License Info.


buraisu

Recommended Posts

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?
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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? 
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

[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 1L4

The addresses are listed like this
39994 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
Link to comment
Share on other sites

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.