Tools.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Tools;
  3. class Tools{
  4. public static function isStop(){
  5. if(file_exists(base_path('.stop'))){
  6. return true;
  7. }else{
  8. return false;
  9. }
  10. }
  11. public static function getWordEn($strIn)
  12. {
  13. $out = str_replace(["ā","ī","ū","ṅ","ñ","ṭ","ḍ","ṇ","ḷ","ṃ"],
  14. ["a","i","u","n","n","t","d","n","l","m"], $strIn);
  15. return ($out);
  16. }
  17. public static function PaliReal($inStr): string {
  18. if (!is_string($inStr)) {
  19. return "";
  20. }
  21. $paliLetter = "abcdefghijklmnoprstuvyāīūṅñṭḍṇḷṃ";
  22. $output = [];
  23. $inStr = strtolower($inStr);
  24. for ($i=0; $i < mb_strlen($inStr,"UTF-8"); $i++) {
  25. # code...
  26. if(strstr($paliLetter,$inStr[$i]) !==FALSE){
  27. $output[] = $inStr[$i];
  28. }
  29. }
  30. return implode('',$output);
  31. }
  32. private static function convert($array,$xml){
  33. foreach ($array as $key => $line) {
  34. # code...
  35. if(!is_array($line)){
  36. $data = $xml->addChild($key,$line);
  37. }else{
  38. if(isset($line['value'])){
  39. $value = $line['value'];
  40. unset($line['value']);
  41. }else{
  42. $value = "";
  43. }
  44. $obj = $xml->addChild($key,$value);
  45. if(isset($line['status'])){
  46. $obj->addAttribute('status',$line['status']);
  47. unset($line['status']);
  48. }
  49. Tools::convert($line,$obj);
  50. }
  51. }
  52. return $xml;
  53. }
  54. public static function JsonToXml($inArray){
  55. $xmlObj = simplexml_load_string("<word></word>");
  56. $xmlDoc = Tools::convert($inArray,$xmlObj);
  57. return $xmlDoc->asXml();
  58. }
  59. }