Tools.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Tools;
  3. class Tools{
  4. public static function getWordEn($strIn)
  5. {
  6. $out = str_replace(["ā","ī","ū","ṅ","ñ","ṭ","ḍ","ṇ","ḷ","ṃ"],
  7. ["a","i","u","n","n","t","d","n","l","m"], $strIn);
  8. return ($out);
  9. }
  10. public static function JsonToXml($inArray){
  11. $xmlObj = simplexml_load_string("<word></word>");
  12. function convert($array,$xml){
  13. foreach ($array as $key => $line) {
  14. # code...
  15. if(!is_array($line)){
  16. $data = $xml->addChild($key,$line);
  17. }else{
  18. if(isset($line['value'])){
  19. $value = $line['value'];
  20. unset($line['value']);
  21. }else{
  22. $value = "";
  23. }
  24. $obj = $xml->addChild($key,$value);
  25. if(isset($line['status'])){
  26. $obj->addAttribute('status',$line['status']);
  27. unset($line['status']);
  28. }
  29. convert($line,$obj);
  30. }
  31. }
  32. return $xml;
  33. }
  34. $xmlDoc = convert($inArray,$xmlObj);
  35. return $xmlDoc->asXml();
  36. }
  37. }