Kan iemand mij misschien vertellen waarom de volgende code alleen de eerste <img ... >...</img> parsed en niet de 2e?
code:
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
| <?php class xml { var $parser; var $stack = array(); function xml() { $this->parser = xml_parser_create(); xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); xml_set_object($this->parser, &$this); xml_set_element_handler($this->parser, "tag_open", "tag_close"); xml_set_character_data_handler($this->parser, "cdata"); } function parse($data) { xml_parse($this->parser, $data, true); while (!xml_parse) { $this->parse(&$data); } } function tag_open($parser, $tag, $attributes) { if ($tag == 'img') { array_push($this->stack, $attributes['src']); } } function cdata($parser, $cdata) { } function tag_close($parser, $tag) { } } // end of class xml $xml_parser = new xml(); $xml_parser->parse("[img]'hallo'>beschrijving</img><img[/img]beschrijving</img>"); foreach ($xml_parser->stack as $value) { print($value); } ?> |