我正在试图弄清楚如何从eve-online kill邮件中只读取数据库所需的几行:
2011.12.30 23:26
受害者:Annabel Lust
Corp:Shadow Monolith
联盟:xXDEATHXx的影子
派系:无 毁灭:猎豹
系统:C6CG-W
安全性:0.0
受到的伤害:827参与方:
姓名:Milena Dush
安全性:0.6
Corp:nXo
联盟:无畏交叉 派系:无 船:猎犬
武器:Caldari Navy Bane Torpedo
损坏程序:457被摧毁的物品:
姐妹们扩大了探测器发射器 催化冷气电弧喷射推进器
纳米纤维内部结构II 超速喷油器系统II 硬连线 - Genolution Core Augmentation CA-2(Cargo)
纳米工程(货运)
姐妹核心扫描仪探测器,数量:5(货物)
微型辅助动力核心I(货物)
姐妹深空扫描仪探测器,数量:5(货物)丢弃物品:
隐蔽行动隐形装置II
Sisters Combat Scanner Probe,数量:5 Warp Disruptor II
纳米纤维内部结构II 天体测量精确定位(货物)
小重力电容升级I,数量:2(货物)
Salvager I(Cargo)
拦截器(货物)
热力学(货物)
协处理器I(货物)
当用户将killmail输入到多文本框中时,我只需要读取已销毁的项目并删除项目,并将数量放在单独的字符串中。
有办法吗?
答案 0 :(得分:0)
您可以使用explode(分隔符,文本)将文本拆分为两个和数组。 例: $海峡=爆炸( “:”, “YourText”);
答案 1 :(得分:-1)
<?php
$str = " 2011.12.30 23:26
Victim: Annabel Lust
Corp: Shadow Monolith
Alliance: Shadow of xXDEATHXx
Faction: None
Destroyed: Cheetah
System: C6CG-W
Security: 0.0
Damage Taken: 827
Involved parties:
Name: Milena Dush
Security: 0.6
Corp: nXo
Alliance: Intrepid Crossing
Faction: None
Ship: Hound
Weapon: Caldari Navy Bane Torpedo
Damage Done: 457
Destroyed items:
Sisters Expanded Probe Launcher
Catalyzed Cold-Gas Arcjet Thrusters
Nanofiber Internal Structure II
Overdrive Injector System II
Hardwiring - Genolution Core Augmentation CA-2 (Cargo)
Nanite Engineering (Cargo)
Sisters Core Scanner Probe, Qty: 5 (Cargo)
Micro Auxiliary Power Core I (Cargo)
Sisters Deep Space Scanner Probe, Qty: 5 (Cargo)
Dropped items:
Covert Ops Cloaking Device II
Sisters Combat Scanner Probe, Qty: 5
Warp Disruptor II
Nanofiber Internal Structure II
Astrometric Pinpointing (Cargo)
Small Gravity Capacitor Upgrade I, Qty: 2 (Cargo)
Salvager I (Cargo)
Interceptors (Cargo)
Thermodynamics (Cargo)
Co-Processor I (Cargo)
";
var_dump(parseItems('/Destroyed items:(?P<destroyedItems>.*)Dropped items:/is', $str, 1));
var_dump(parseItems('/Dropped items:(?P<droppedItems>.*)/is', $str, 1));
function parseItems($regex, $str, $defaultQty = 0){
preg_match($regex, $str, $match);
$lines = explode("\n", $match[1]);
$defaultQty = 0;
$items = array();
foreach($lines as $key => $line){
$line = trim($line);
if($line != ""){
$quantity = (strpos($line, "Qty:") != false) ? getQty($line) : $defaultQty;
$items[] = array($line => $quantity);
}
}
return $items;
}
function getQty($line){
preg_match('/, Qty:\s+(?P<quantity>[0-9]+)/', $line, $match);
return $match['quantity'];
}
这应该为您提供一系列已删除和已销毁的线及其数量。它返回关联数组,其中key是行,value是数量。