-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskidka.php
More file actions
61 lines (50 loc) · 1.46 KB
/
skidka.php
File metadata and controls
61 lines (50 loc) · 1.46 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
class SuperParser
{
protected $_stack = array();
protected $_models = array();
protected $_file = "";
protected $_parser = null;
protected $_currentId = "";
protected $_current = "";
public function __construct($file)
{
$this->_file = $file;
$this->_parser = xml_parser_create("UTF-8");
xml_set_object($this->_parser, $this);
xml_set_element_handler($this->_parser, "startTag", "endTag");
xml_set_character_data_handler($this->_parser, "contents");
}
public function contents($parser, $data) {
if ($this->_current == "MODEL") {
array_push($this->_models,$data);
}
if ($this->_models && count($this->_models) >= 10 ) {
echo implode("\n", $this->_models);
echo "\n";
die;
}
}
public function startTag($parser, $name, $attribs)
{
array_push($this->_stack, $this->_current);
$this->_current = $name;
}
public function endTag($parser, $name)
{
$this->_current = array_pop($this->_stack);
}
public function parse()
{
$fh = fopen($this->_file, "r");
if (!$fh) {
die("Epic fail!\n");
}
while (!feof($fh)) {
$data = fread($fh, 4096);
xml_parse($this->_parser, $data, feof($fh));
}
}
}
$parser = new SuperParser("https://s3-eu-west-1.amazonaws.com/opsway-share/g.xml");
$parser->parse();