Browse Source

convert 放外面

visuddhinanda 2 years ago
parent
commit
82376cb3d6
1 changed files with 36 additions and 21 deletions
  1. 36 21
      app/Tools/Tools.php

+ 36 - 21
app/Tools/Tools.php

@@ -9,31 +9,46 @@ class Tools{
                             ["a","i","u","n","n","t","d","n","l","m"], $strIn);
             return ($out);
         }
-    public static function JsonToXml($inArray){
-        $xmlObj = simplexml_load_string("<word></word>");
-        function convert($array,$xml){
-            foreach ($array as $key => $line) {
-                # code...
-                if(!is_array($line)){
-                    $data = $xml->addChild($key,$line);
+    public static function PaliReal($inStr): string {
+        if (!is_string($inStr)) {
+            return "";
+        }
+        $paliLetter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
+        $output = [];
+        $inStr = strtolower($inStr);
+        for ($i=0; $i < mb_strlen($inStr,"UTF-8"); $i++) {
+            # code...
+            if(strstr($paliLetter,$inStr[$i]) !==FALSE){
+                $output[] = $inStr[$i];
+            }
+        }
+        return implode('',$output);
+    }
+    private static function convert($array,$xml){
+        foreach ($array as $key => $line) {
+            # code...
+            if(!is_array($line)){
+                $data = $xml->addChild($key,$line);
+            }else{
+                if(isset($line['value'])){
+                    $value = $line['value'];
+                    unset($line['value']);
                 }else{
-                    if(isset($line['value'])){
-                        $value = $line['value'];
-                        unset($line['value']);
-                    }else{
-                        $value = "";
-                    }
-                    $obj = $xml->addChild($key,$value);
-                    if(isset($line['status'])){
-                        $obj->addAttribute('status',$line['status']);
-                        unset($line['status']);
-                    }
-                    convert($line,$obj);
+                    $value = "";
+                }
+                $obj = $xml->addChild($key,$value);
+                if(isset($line['status'])){
+                    $obj->addAttribute('status',$line['status']);
+                    unset($line['status']);
                 }
+                Tools::convert($line,$obj);
             }
-            return $xml;
         }
-        $xmlDoc = convert($inArray,$xmlObj);
+        return $xml;
+    }
+    public static function JsonToXml($inArray){
+        $xmlObj = simplexml_load_string("<word></word>");
+        $xmlDoc = Tools::convert($inArray,$xmlObj);
         return $xmlDoc->asXml();
     }
 }