0

I need to parse this .txt database which is not delimited, it's by position. Each field has a start position, end position and length.

I'm going to INSERT this into a MySQL TABLE, but I have to create the layout and working how this data should be defined as an array or as Objects?

Here is a link to the record layout: http://www.state.nj.us/treasury/taxation/lpt/MODIV-Counties/2013/MODIVLayout.pdf

4

1 に答える 1

1

レコードは 700 文字の長さの文字列になります。これらの文字列の配列があります。各文字列は、オブジェクトまたはハッシュに変換する必要があります。

$record_strings = array(
    'DATADATADATADATA...DATADATADATADATADATADATA',
    'DATADATADATADATA...DATADATADATADATADATADATA',
    'DATADATADATADATA...DATADATADATADATADATADATA',
    'DATADATADATADATA...DATADATADATADATADATADATA',
    'DATADATADATADATA...DATADATADATADATADATADATA',
    'DATADATADATADATA...DATADATADATADATADATADATA',
);
$record_hashes = array_map(function($record_string) {
    return array(
        'COUNTY-DISTRICT' => substr($record_string, 0, 4),
        'BLOCK' => substr($record_string, 4, 9),
        'LOT' => substr($record_string, 13, 9),
        ...
    );
}, $record_strings);

これで、反復処理やデータベースへの挿入など、より簡単に処理できるハッシュの配列ができました。

于 2013-06-25T21:28:08.390 に答える