Created
June 22, 2014 17:25
-
-
Save shawnsandy/c3faf36014d841130ece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $string = "hrlle worls fff test i all rightt ..." ; | |
| $pattern = '/ /'; | |
| $string1 = preg_replace($pattern, ' ', $string); | |
| //var_dump($string1); | |
| //var_dump (preg_replace($pattern, $string1)) ; | |
| $string_1 = '%FLSPRING HILL^SANDY$SHAWN$JASON^342 GLENN IVY TER^ ?;6360101953079071446=2012197199060=?#! 34608 E B 1507 ECCECC00000?'; | |
| $string_2 = '%FLWEEKI^PIERSON$WILLIAM$HOWARD^11195 MARSH WREN AVE^ ?;6360101662592871391=1810197199310=?#! 346143034 E B 1602 ECCECC00000?'; | |
| //echo "trimmed " . trim($string_2); | |
| function decode_id($data) { | |
| if(!isset($data)) {return false;} | |
| $return = array( | |
| 'first_name' => null, | |
| 'last_name' => null, | |
| 'middle_name' => null, | |
| 'id_number' => null, | |
| 'birth_month' => null, | |
| 'birth_day' => null, | |
| 'birth_year' => null, | |
| 'id_full' => null, | |
| 'success' => true); | |
| $return['success'] = true; | |
| if (preg_match("/(\w{2})(.*?)\^(.*?)\^(.*?)\?;(\d+)=(\d+)=\?/", $data, $my_results)) { | |
| $return['street'] = $my_results[4]; | |
| $return['state'] = $my_results[1]; | |
| $return['city'] = $my_results[2]; | |
| $full_name = $my_results[3]; | |
| $name_parts = explode('$',$full_name); | |
| $return['first_name'] = $name_parts[1]; | |
| $return['last_name'] = $name_parts[0]; | |
| $return['middle_name'] = $name_parts[2]; | |
| $id_raw = $my_results[5]; | |
| $return['id_number'] = substr($id_raw,8,11); | |
| $birth_raw = $my_results[6]; | |
| $return['birth_month'] = substr($birth_raw,2,2); | |
| $return['birth_day'] = substr($birth_raw,10,2); | |
| $return['birth_year'] = substr($birth_raw,4,4); | |
| } | |
| if (preg_match("/(\w{2})(.*?)\^(.*?)\^(.*?)\^(.*?)\?;(\d+)=(\d+)=\?/", $data, $my_results)) { | |
| $return['street'] = $my_results[4]; | |
| $return['state'] = $my_results[1]; | |
| $return['city'] = $my_results[2]; | |
| $full_name = $my_results[3]; | |
| $name_parts = explode('$',$full_name); | |
| $return['first_name'] = $name_parts[1]; | |
| $return['last_name'] = $name_parts[0]; | |
| $return['middle_name'] = $name_parts[2]; | |
| $id_raw = $my_results[6]; | |
| $return['id_number'] = substr($id_raw,8,11); | |
| $birth_raw = $my_results[7]; | |
| $return['birth_month'] = substr($birth_raw,2,2); | |
| $return['birth_day'] = substr($birth_raw,10,2); | |
| $return['birth_year'] = substr($birth_raw,4,4); | |
| } | |
| if (preg_match("/(\w{2})(.*?)\^(.*?)\^(.*?)\^(.*?)\?;(\d+)=(\d+)=\?#!(\s+)(\d{5,})(.*?)\?/", $data, $my_results)) { | |
| $return['street'] = $my_results[4]; | |
| $return['state'] = $my_results[1]; | |
| $return['city'] = $my_results[2]; | |
| $full_name = $my_results[3]; | |
| $name_parts = explode('$',$full_name); | |
| $return['first_name'] = $name_parts[1]; | |
| $return['last_name'] = $name_parts[0]; | |
| $return['middle_name'] = $name_parts[2]; | |
| $id_raw = $my_results[6]; | |
| $return['id_number'] = substr($id_raw,8,11); | |
| $birth_raw = $my_results[7]; | |
| $return['birth_month'] = substr($birth_raw,2,2); | |
| $return['birth_day'] = substr($birth_raw,10,2); | |
| $return['birth_year'] = substr($birth_raw,4,4); | |
| $return['zip_code'] = $my_results[9]; | |
| $return['zip_code'] = substr($return['zip_code'], 0, 5); | |
| } | |
| $return['id_full'] = substr($return['last_name'],0,1) . $return['id_number']; | |
| foreach($return as $k => $v) { | |
| if(empty($return[$k])) { | |
| $return['success'] = false; | |
| $return['message'] = 'ID card swipe issue (Not all info present). <br/>Please swipe again.'; | |
| } | |
| } | |
| return $return ; | |
| } | |
| if(isset($_POST['id_card'])) | |
| $v = decode_id($string_1); | |
| ?> | |
| <form action="./" method="post"> | |
| <input type="text" name="id_card" autofocus="autofocus" style="width: 80%; padding: 20px;"> | |
| </form> | |
| <pre> | |
| <?php if(isset($v)) var_dump($v); ?> | |
| </pre> | |
| <script type='text/javascript'>//<![CDATA[ | |
| ;document.write("<script async src='//HOST:3000/browser-sync-client.1.0.0.js'><\ | |
| /script>".replace(/HOST/g, location.hostname)); | |
| //]]></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment