-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-parser.php
More file actions
27 lines (19 loc) · 896 Bytes
/
Copy pathxml-parser.php
File metadata and controls
27 lines (19 loc) · 896 Bytes
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
<?php
function ParseXML($pathToXML) {
$XMLFileContents = file_get_contents($pathToXML) or die("XML file not found.");
$XMLContentsArray = preg_split('/(<|>)/', $XMLFileContents);
$XMLContentsArray = preg_grep('/^($|\n {0,}|\r {0,}|\r\n {0,})/', $XMLContentsArray, PREG_GREP_INVERT);
$parsedXMLData = [];
$arrayCurrentIndex = 0;
foreach($XMLContentsArray as $element) {
if(preg_match('/^section id="\w{1,}" visibility="[0|1]"/', $element)) {
$match;
preg_match('/id="(\w{1,})"/', $element, $match, PREG_OFFSET_CAPTURE);
$parsedXMLData[$arrayCurrentIndex]['id'] = $match[1][0];
preg_match('/visibility="([0|1])"/', $element, $match, PREG_OFFSET_CAPTURE);
$parsedXMLData[$arrayCurrentIndex]['visibility'] = $match[1][0];
$arrayCurrentIndex++;
}
}
return $parsedXMLData;
}