2016-01-01 13:42:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
class ParseXML {
|
2017-01-24 08:45:11 +01:00
|
|
|
|
2016-01-01 13:42:52 +01:00
|
|
|
public function __construct() {
|
2017-01-24 08:45:11 +01:00
|
|
|
return true;
|
2016-01-01 13:42:52 +01:00
|
|
|
}
|
2017-01-24 08:45:11 +01:00
|
|
|
|
2016-01-01 13:42:52 +01:00
|
|
|
public function GetElement($InputString, $ElementName) {
|
2025-10-14 15:15:20 +02:00
|
|
|
// Sanitize element name to prevent XML injection
|
|
|
|
|
$ElementName = preg_replace('/[^a-zA-Z0-9_\-\s]/', '', $ElementName);
|
|
|
|
|
|
|
|
|
|
if (strpos($InputString, "<".$ElementName.">") === false) return false;
|
|
|
|
|
if (strpos($InputString, "</".$ElementName.">") === false) return false;
|
|
|
|
|
|
|
|
|
|
$Element = substr($InputString, strpos($InputString, "<".$ElementName.">")+strlen($ElementName)+2, strpos($InputString, "</".$ElementName.">")-strpos($InputString, "<".$ElementName.">")-strlen($ElementName)-2);
|
|
|
|
|
|
|
|
|
|
// Strip any remaining HTML/XML tags from the content
|
|
|
|
|
return strip_tags($Element);
|
2016-01-01 13:42:52 +01:00
|
|
|
}
|
2017-01-24 08:45:11 +01:00
|
|
|
|
2016-01-01 13:42:52 +01:00
|
|
|
public function GetAllElements($InputString, $ElementName) {
|
2025-10-14 15:15:20 +02:00
|
|
|
// Sanitize element name to prevent XML injection
|
|
|
|
|
$ElementName = preg_replace('/[^a-zA-Z0-9_\-\s]/', '', $ElementName);
|
|
|
|
|
|
|
|
|
|
$Elements = array();
|
|
|
|
|
while (strpos($InputString, $ElementName) !== false) {
|
|
|
|
|
$element = $this->GetElement($InputString, $ElementName);
|
|
|
|
|
if ($element !== false) {
|
|
|
|
|
$Elements[] = $element;
|
|
|
|
|
}
|
|
|
|
|
$InputString = substr($InputString, strpos($InputString, "</".$ElementName.">")+strlen($ElementName)+3, strlen($InputString));
|
|
|
|
|
}
|
|
|
|
|
return $Elements;
|
2016-01-01 13:42:52 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-24 08:45:11 +01:00
|
|
|
}
|
2016-01-01 13:42:52 +01:00
|
|
|
|
2017-01-24 08:45:11 +01:00
|
|
|
?>
|