-3
I have a text file inside it contains coupons follows example of a coupon:
COTIA CENTRO
ATACADAO S.A.
PROF JOSE BARRETO
-----------------------------------------------
CNPJ 00.000.000/0000-00
IE 000.000.000.000
IM ISENTO
-----------------------------------------------
G Extrato No. 182863Gþ
G CUPOM FISCAL ELETRâNICO - SATGþ
-----------------------------------------------
#|COD|DESC|QTD|UN|VL UN R$|(VL TR R$)*|VL ITEM
-----------------------------------------------
001 00071162 AGUA COCO C.JORDAO 1X200ML
6 UND9 X 1,49 (1,72) 8,94
desconto sobre item -1,20
002 00001650 COCO SECO TROPIC. 1X1Kg
0,828 KG9 X 3,99 (0,73) 3,30
Total bruto de Itens 12,24
Total de descontos/acrescimos sobre item -1,20
GTOTAL R$ 11,04Gþ
Vale Alimentacao 11,04
-----------------------------------------------
OBSERVACOES DO CONTRIBUINTE
*Valor aproximado dos tributos do item
Valor aproximado dos tributos deste cupom
(conforme Lei Fed.12.741/2012) R$ 2,45
Vlr.Aprox.Tributos: Federal R$0,47 (4,26%)
Vlr.Aprox.Tributos: Estadual R$1,98 (17,93%)
Fonte: IBPT.
-----------------------------------------------
CIELO-VEROCARD BENEFICIO
000000******0000
PDV=75151429 DOC=140068 AUT=938956
VALOR:11,04 S.DISP:1.166,06 (SiTef)
-----------------------------------------------
G SAT No. 00000000Gþ
14/06/2021 - 08:27:29
G 0000 0000 0000 0000 0000 0000 Gþ
G 0000 0000 0000 0000 0000 Gþ
CFe35210675315333005925590002843141828638739062|20210614082729|11.04||jf6L4XuLg/T9PyMFRUoWGyqCQZG+YgzerKsDm7GLllv/w6BFvDKIBsRemosUSKyOsDfMkS2Bds+yXqrucQa1zmu2HpVlWxF8qu+M3MB7uMRub5H1NibCZAmQBY7MbXiXQm/0lC4jzG2rnDrmlI19OtJQDgODNDySgTViB3xiQmQVbF/jjM5aLnwZ9wNWReMI4uQHB/Dd3N8w8OVTxEPx7N3p27KGskS/5EmbNc1EX+nhHVNYkOQCzEi5ip0pALN3EzvD/p4b11ThNt697UhM7mRaavjapoEDBBTIrUx1YxOQyWPfeflarB72rePPzpbM9daRvvtkNu7LAxeO/46oOg==
-----------------------------------------------
TPLinux AT.14.c00N-19.07 - Unisys Brasil Ltda
-----------------------------------------------
4610-CR2 VERSAO:16.05 PDV:002 LJ:059
OPR:000243418Tatiana Lig 14/06/2021 08:27:33
All coupons start with COTIA CENTRO
and end in OPR:...
I want to do a search and find a specific coupon based on the number of the Extrato
or TOTAL
and if you find it return me this coupon.
I tried using Regex:
$caminho = 'arqEspelho.txt';
$espelho = file_get_contents ($caminho);
$re = '/(?=\s{17}COTIA CENTRO).+?(.+?OPR:.\d+\w+\s\w+\s+\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}:\d{2})/s';
preg_match_all($re, $espelho, $matches, PREG_SET_ORDER, 0);
echo '<pre>';
var_dump($matches);
However it returns in Multi Array and do not know how to do this search How could I perform this search? Would you have some easier way to separate the coupons to perform the search?
Using this file link as an example, when I get the coupon for both the extract (182862) and the value (66.81), it is returning the same coupon twice and the second time the coupon is coming extra items until the second way. Example - 1st Coupon link Example - 2nd Coupon link
– Leandro Pio
@Leandropio The problem is that in that file The coupons have the OPR line, then have a line with "zucchini", then have several other lines and another OPR. That is, he finishes the first coupon, but before starting another one (i.e., before finding "COTIA CENTRO"), he finds another ending (another "OPR"). If a coupon can have more than one OPR, then you have to change the code. But if each coupon can only have one OPR, then the file is wrong
– hkotsubo
I get it, is that that would be the second way of the voucher, would I have to finish the coupon as soon as I found the first correct OPR? How could I do that? Thank you very much for the great help
– Leandro Pio
@Leandropio would probably have to have one more control variable (type
$encontrei_opr
) which indicates whether you have already found the OPR and have not yet reached another coupon. And then you ignore the second way, for example...– hkotsubo