$txt = <<
934030913 G 9RUPISOLV 20BUST 00001 P 04
0055 G 0CIBALGINA DUE FAST*24CPR 200MG 00001 P 01
EOL;
$specialChars = preg_quote( '#$%^&*()+=-[]\';,./{}|\":<>?~', '#' );
preg_match_all(
'#([0-9]{4,9}\s+[A-Z]{1}\s+([' . $specialChars . 'A-Z0-9 ]+)\s+([0-9]{3,7})n?\s+P\s+([0-9]+))#',
$txt, $match
);
Array example:
[0] => Array ( [0] => 934030913 G 9RUPISOLV 20BUST 00001 P 04
[1] => 0055 G 0CIBALGINA DUE FAST*24CPR 200MG 00001 P 01 )
[1] => Array ( [0] => 934030913 G 9RUPISOLV 20BUST 00001 P 04
[1] => 0055 G 0CIBALGINA DUE FAST*24CPR 200MG 00001 P 01 )
[2] => Array ( [0] => 9RUPISOLV 20BUST
[1] => 0CIBALGINA DUE FAST*24CPR 200MG )
[3] => Array ( [0] => 00001
[1] => 00002 )
[4] => Array ( [0] => 04
[1] => 01) )
I need insert match[2][x] match[3][x] match[4][x] (of all results) in a mysql db, i think with foreach but i don't know how!
[2] => Array ( [x] => PRODUCT ) in product column |
[3] => Array ( [x] => QUANTITY) in quantity column | ONE RECORD
[4] => Array ( [x] => NUMBER ) in terminal column |
How i can do that?
What I have tried:
$indexes = array(2, 3, 4);
foreach ($indexes as $index) {
foreach ($match[$index] as $value) {
$sql = "INSERT INTO `table`(`product`) VALUES ('{$value}');"; mysql_query($sql); } }
?>
解决方案
txt = <<
934030913 G 9RUPISOLV 20BUST 00001 P 04
0055 G 0CIBALGINA DUE FAST*24CPR 200MG 00001 P 01
EOL;
specialChars = preg_quote( '#
%^&*()+=-[]\';,./{}|\":<>?~', '#' );
preg_match_all(
'#([0-9]{4,9}\s+[A-Z]{1}\s+([' .