Преглед изворни кода

added functions isXML and testAndFormatString

CauseFX пре 3 година
родитељ
комит
3bc2d1c7d2
1 измењених фајлова са 18 додато и 0 уклоњено
  1. 18 0
      api/functions/organizr-functions.php

+ 18 - 0
api/functions/organizr-functions.php

@@ -885,4 +885,22 @@ trait OrganizrFunctions
 	{
 		return is_string($string) && is_array(json_decode($string, true)) && (json_last_error() == JSON_ERROR_NONE);
 	}
+
+	public function isXML($string)
+	{
+		libxml_use_internal_errors(true);
+		return (bool)simplexml_load_string($string);
+	}
+
+	public function testAndFormatString($string)
+	{
+		if ($this->isJSON($string)) {
+			return ['type' => 'json', 'data' => json_decode($string, true)];
+		} elseif ($this->isXML($string)) {
+			libxml_use_internal_errors(true);
+			return ['type' => 'xml', 'data' => simplexml_load_string($string)];
+		} else {
+			return ['type' => 'string', 'data' => $string];
+		}
+	}
 }