Last active
December 21, 2015 01:59
-
-
Save andersonfraga/6231913 to your computer and use it in GitHub Desktop.
Parser
This file contains 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 | |
$txt = array( | |
'08 11', | |
'08110054 00432 0000 15 27 4597 00 065001017', | |
'08110629 00017 0000 I 4597 1528 00 4597', | |
'08110641 00015 0000 J 4597 4595 00 4597', | |
'08110643 00005 0000 J 4595 4597 00 4595', | |
'08110647 00008 0000 J 4595 4597 00 4595', | |
'08110713 01058 0000 I 4597 1528 00 4597', | |
'08110714 00013 0000 I 4597 1621 00 4597', | |
'08110718 00424 0000 15 28 4597 00 065001018', | |
'08110722 00000 0000 I 4597 1730 00 4597', | |
'08110733 00221 0000 I 4597 1528 00 4597', | |
'08110755 00234 0000 J 4597 4613 00 4597', | |
'08110755 00000 0000 CO 15 28 4597 00 065001019', | |
'08110823 00000 0000 CI 4595 5198288960 00 4595', | |
'08110851 00450 0000 I 4595 1789 00 4595', | |
'08110948 00000 0000 K 20 4595 00', | |
'08110956 00000 0000 K 5198288960 4595 00', | |
'08110957 00000 0000 CO 0 43 98288960 4595 00 165001002', | |
'08111015 01000 0000 J 4597 4595 00 4597', | |
'08111107 00003 0000 M 0 43 95540779 4597 00 165001001', | |
'08111108 00015 0000 M 0 43 80152132 4597 00 165001002', | |
'08111123 00024 0000 J 4597 4614 00 4597', | |
'08111246 00033 0000 M 0 4886 0154733668028 4595 00 030001004', | |
'08111303 00035 0000 I 4595 1789 00 4595', | |
' 08111327 00000 0000 CO 17 89 4595 00 065001020', | |
'08111331 00000 0000 CI 4595 1789 00 4595', | |
'08111337 00105 0000 17 89 4595 00 065001001', | |
'08111354 00547 0000 I 4595 1789 00 4595', | |
'08111406 00001 0000 J 4597 4595 00 4597', | |
'08111408 00228 0000 J 4597 4595 00 4597', | |
'08111435 00000 0000 CI 4555 5197297624 00 4555', | |
'08111807 00000 0000 CI 4595 5182605567 00 4595', | |
'08111809 00100 0000 I 4595 5182605567 00 4595', | |
'08111815 00129 0000 J 4597 4595 00 4597', | |
'08111908 00117 0000 I 4597 1621 00 4597', | |
); | |
$pattern = '/(\s+)?([0-9]+)\s+([0-9]+)\s+([0-9]+)\s+(([A-Z]+)|\s)\s+(([0-9]+)|\s)\s+(([0-9]{2,})|\s)\s+([0-9]{2,})\s+([0-9]{4,})\s+([0-9]+)(\s+([0-9]+))?$/'; | |
echo '<table border=1>'; | |
foreach ($txt as $value) { | |
preg_match($pattern, $value, $matches); | |
echo '<tr>'; | |
echo "<td>{$matches[2]}</td>"; | |
echo "<td>{$matches[3]}</td>"; | |
echo "<td>{$matches[4]}</td>"; | |
echo "<td>{$matches[6]}</td>"; | |
echo "<td>{$matches[8]}</td>"; | |
echo "<td>{$matches[10]}</td>"; | |
echo "<td>{$matches[11]}</td>"; | |
echo "<td>{$matches[12]}</td>"; | |
echo "<td>{$matches[13]}</td>"; | |
echo "<td>{$matches[14]}</td>"; | |
echo '</tr>'; | |
} | |
echo '</table>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment