Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Danny Froberg
bolistfileparser
Commits
cd2ab316
Commit
cd2ab316
authored
Apr 08, 2019
by
Danny Froberg
💬
Browse files
Added more tests
parent
a6fa203b
Changes
1
Hide whitespace changes
Inline
Side-by-side
parse.php
View file @
cd2ab316
...
...
@@ -12,6 +12,7 @@ require_once "includes/definitions.php";
*/
function
bulid_field_desc
(
$field_head
,
$field_desc
)
{
global
$field_len
;
$field_len
=
0
+
(
mb_strlen
(
"
\r\n
"
));
$fi
=
0
;
foreach
(
$field_desc
as
$key
)
{
switch
(
$key
[
5
])
{
...
...
@@ -57,19 +58,23 @@ function process_fields( $fields ) {
echo
$fields
[
'BOPREAN'
]
.
"
\t
"
.
$fields
[
'BOARTL'
]
.
"
\t
"
.
$fields
[
'BOBNL1'
]
.
"
\t
"
.
$fields
[
'BOBNL2'
]
.
"
\t
"
.
make_price
(
$fields
[
'BOPRIS'
],
2
)
.
"
\t
"
.
$fields
[
'BOENH'
]
.
"
\t
"
.
make_price
(
$fields
[
'BOPC1'
])
.
"
\n
"
;
}
function
parse
()
{
function
get_file
(
$file_name
)
{
$file_size
=
filesize
(
$file_name
);
$file_desc
=
fopen
(
$file_name
,
'rb'
)
or
die
(
"can't open file"
);
$file_buff
=
fread
(
$file_desc
,
$file_size
);
fclose
(
$file_desc
)
or
die
(
"can't close file"
);
return
$file_buff
;
}
function
parse
(
$file_name
)
{
global
$field_head
,
$field_desc
,
$field_len
;
// Build Head
$descriptor
=
bulid_field_desc
(
$field_head
,
$field_desc
);
// Read in file
$file_name
=
'./tests/aaa_readfile.txt'
;
$file_size
=
filesize
(
$file_name
);
$file_desc
=
fopen
(
$file_name
,
'rb'
)
or
die
(
"can't open file"
);
$buffer
=
fread
(
$file_desc
,
$file_size
);
$chunks
=
str_split
(
$buffer
,
$field_len
);
$i
=
1
;
foreach
(
$chunks
as
$lines
)
{
$file_buff
=
get_file
(
$file_name
);
$file_chunks
=
str_split
(
$file_buff
,
$field_len
);
$pretty_numbered_lines
=
1
;
foreach
(
$file_chunks
as
$lines
)
{
// $buffer_conv = mb_convert_encoding($lines,'auto', 'CP850');
$line
=
unpack
(
$descriptor
,
$lines
);
array_walk_recursive
(
$line
,
'myEncodeFunction'
);
...
...
@@ -80,22 +85,18 @@ function parse() {
var_dump
(
$line
);
exit
();
}
$fields
[]
=
$line
;
//Save for later.
// var_dump( array_chunk( $line, count( $field_desc ), true ) );
echo
sprintf
(
"%06d"
,
$i
)
.
"
\t
"
;
$i
++
;
echo
sprintf
(
'%06d'
,
$pretty_numbered_lines
)
.
"
\t
"
;
$pretty_numbered_lines
++
;
process_fields
(
$line
);
}
echo
'count: '
.
count
(
$field_desc
)
.
"
\n
"
;
echo
'lines: '
.
count
(
$chunks
)
.
"
\n
"
;
echo
'lines: '
.
count
(
$
file_
chunks
)
.
"
\n
"
;
echo
'field len: '
.
$field_len
.
"
\n
"
;
//var_dump( $fields );
fclose
(
$file_desc
)
or
die
(
"can't close file"
);
}
// Test
parse
();
\ No newline at end of file
parse
(
'./tests/aaa_readfile.txt'
);
parse
(
'./tests/V1412362.TXT'
);
parse
(
'./tests/V1415377.TXT'
);
parse
(
'./tests/V1414924.TXT'
);
parse
(
'./tests/V1417312.TXT'
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment