-
Notifications
You must be signed in to change notification settings - Fork 4
/
parseInventory.inc
40 lines (35 loc) · 1.12 KB
/
parseInventory.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
require_once __DIR__."/ffxivData.inc";
function parse_file($dataset, $file, &$inventory = [])
{
$needle = "item-list__list";
$lastPos = 0;
$content = file_get_contents($file);
while (($lastPos = strpos($content, $needle, $lastPos)) !== false) {
$stack = strpos($content, 'data-stack', $lastPos);
$sub = substr($content, $stack);
$preg = "/data-stack=\"(.*?)\"/si";
preg_match($preg, $sub, $ui);
$preg = "/db-tooltip__item__name[^>]*>(.*?)</si";
preg_match($preg, $sub, $name);
$name = html_entity_decode($name[1]);
$item = $dataset->getItem($name);
if (array_key_exists($item->Index, $inventory)) {
$inventory[$item->Index]['count'] += $ui[1];
} else {
$inventory[$item->Index] = [
'name' => $item->Name,
'count' => $ui[1]
];
}
$lastPos = $lastPos + strlen($needle);
}
return $inventory;
}
/*
$dataset = new FfxivDataSet();
$i = parse_file($dataset, './Inventory/inv1.html');
$i = parse_file($dataset, './Inventory/inv2.html', $i);
ksort($i);
print_r($i);
*/