get_term_index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /*
  3. 查询term字典
  4. 输入单词列表
  5. 输出查到的结果
  6. */
  7. require_once "../path.php";
  8. require_once "../public/_pdo.php";
  9. $output["status"]=0;
  10. $output["error"]="";
  11. PDO_Connect("sqlite:"._FILE_DB_TERM_);
  12. if(isset($_POST["lang"])){
  13. $lang = $_POST["lang"];
  14. }
  15. else{
  16. $output["status"]=1;
  17. $output["error"]="#no_param lang";
  18. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  19. exit;
  20. }
  21. if(isset($_POST["word"])){
  22. $word = $_POST["word"];
  23. $query ="select word,meaning,language,owner,count(*) as co from term where word=? and language=? group by word,meaning order by co DESC";
  24. $output["data"] = PDO_FetchAll($query,array($word,$lang));
  25. }
  26. else{
  27. $query ="select * from (select word,meaning,language,owner,count(*) as co from term where language=? group by word,meaning order by co DESC) where 1 group by word";
  28. $output["data"] = PDO_FetchAll($query,array($lang));
  29. $pos = mb_strpos($lang,"-",0,"UTF-8");
  30. if($pos){
  31. $lang_family= mb_substr($lang,0,$pos,"UTF-8");
  32. $query ="select * from (select word,meaning,language,owner,count(*) as co from term where language like ? group by word,meaning order by co DESC) where 1 group by word";
  33. $otherlang = PDO_FetchAll($query,array($lang_family."%"));
  34. foreach ($otherlang as $key => $value) {
  35. $output["data"][]=$value;
  36. }
  37. }
  38. }
  39. echo json_encode($output, JSON_UNESCAPED_UNICODE);
  40. ?>