Tools.php 1.9 KB

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