我需要一些建议..。
一旦在我的Magento存储上下了订单,我就有一个观察者来查看事件,并触发使用订单信息生成的txt文件。
然后,GPRS打印机每50秒查看这个txt文件并打印订单。
这是txt文件中一个订单的格式:
# 10 *1*100000190*1;Ice Cream; 15; 1;Coke; 8; 1;Chicken Burger; 33; *15*n/a;71; 4;John Doe;1 test street, City;08:01 13-12-2013; 184;7; n/a;011123123;*#(请注意,"100000190“是唯一的订单号)
一旦订单被打印出来,操作员就可以接受/拒绝订单。然后,接受/拒绝确认将从打印机发送反馈到服务器上的另一个php文件。(此确认将再次包含唯一的订单号)
一旦接收到接受/拒绝确认,应从原始txt文件中删除订单,以免再次读取和处理/打印订单。
因此,在txt文件中将有多个订单,所以当我收到一个订单的确认时,我不能简单地清除内容,因为其他订单就会丢失。
我将如何只删除从txt文件中确认的订单,然后离开其他文件呢?
下面是包含3个订单的txt文件的示例:
10 *1*100000190*1;冰淇淋;15;1;可乐;8;1;鸡汉堡包;33;*15*n/a;71;4;John Doe;1试验街,城市;插入时间属性;184;7;n/a;011123123;*## 10 *1*100000191*1;冰淇淋;15;1;鸡卷;33;*15*n/a;63;4;John Doe;1测试街,城市;填上时间属性;185;7;n/a;011123123;*# 10 *2*100000192*1;鸡卷;33;*n/a;33;4;无名氏;城市试验街1号;插入时间属性;186;7;n/a;011123123;*
感谢你的支持。
发布于 2013-12-13 08:54:06
<?php
// open your file and save to $txt
//$txt = "# 10 *1*100000190*1;Ice Cream; 15; 1;Coke; 8; 1;Chicken Burger; 33; *15*n/a;71; 4;John Doe;1 test street, City;insert time attribute; 184;7; n/a;011123123;*## 10 *1*100000191*1;Ice Cream; 15; 1;Chicken Wrap; 33; *15*n/a;63; 4;John Doe;1 test street, City;insert time attribute; 185;7; n/a;011123123;*## 10 *2*100000192*1;Chicken Wrap; 33; *0*n/a;33; 4;John Doe;1 test street, City;insert time attribute; 186;7; n/a;011123123;*#";
$txt = file_get_contents("yourfile");
$arr = preg_split("/#/", $txt);
$result = "";
foreach($arr as $line) {
if(!empty($line)) {
$components = preg_split("/\*/", $line);
$orderNo = $components[2];
if(checkIfWantToPrint($orderNo)) {
// print and other operations
} else {
// add line
$result .= "#".$line."#";
}
}
}
// save your file with $result value
file_put_contents("yourfile", $result);
?>https://stackoverflow.com/questions/20562328
复制相似问题