Tools.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 PaliReal($inStr): string {
  11. if (!is_string($inStr)) {
  12. return "";
  13. }
  14. $paliLetter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
  15. $output = [];
  16. $inStr = strtolower($inStr);
  17. for ($i=0; $i < mb_strlen($inStr,"UTF-8"); $i++) {
  18. # code...
  19. if(strstr($paliLetter,$inStr[$i]) !==FALSE){
  20. $output[] = $inStr[$i];
  21. }
  22. }
  23. return implode('',$output);
  24. }
  25. private static function convert($array,$xml){
  26. foreach ($array as $key => $line) {
  27. # code...
  28. if(!is_array($line)){
  29. $data = $xml->addChild($key,$line);
  30. }else{
  31. if(isset($line['value'])){
  32. $value = $line['value'];
  33. unset($line['value']);
  34. }else{
  35. $value = "";
  36. }
  37. $obj = $xml->addChild($key,$value);
  38. if(isset($line['status'])){
  39. $obj->addAttribute('status',$line['status']);
  40. unset($line['status']);
  41. }
  42. Tools::convert($line,$obj);
  43. }
  44. }
  45. return $xml;
  46. }
  47. public static function JsonToXml($inArray){
  48. $xmlObj = simplexml_load_string("<word></word>");
  49. $xmlDoc = Tools::convert($inArray,$xmlObj);
  50. return $xmlDoc->asXml();
  51. }
  52. }