mirror of https://github.com/LX3JL/xlxd.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.4 KiB
40 lines
1.4 KiB
<?php
|
|
|
|
class ParseXML {
|
|
|
|
public function __construct() {
|
|
return true;
|
|
}
|
|
|
|
public function GetElement($InputString, $ElementName) {
|
|
// 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);
|
|
}
|
|
|
|
public function GetAllElements($InputString, $ElementName) {
|
|
// 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;
|
|
}
|
|
|
|
}
|
|
|
|
?>
|