pali_sent.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. //查询term字典
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. //is login
  6. if(isset($_COOKIE["username"]) && !empty($_COOKIE["username"])){
  7. $username = $_COOKIE["username"];
  8. }
  9. else{
  10. $username = "";
  11. }
  12. if(isset($_GET["op"])){
  13. $_op=$_GET["op"];
  14. }
  15. else if(isset($_POST["op"])){
  16. $_op=$_POST["op"];
  17. }
  18. if(isset($_GET["word"])){
  19. $_word=mb_strtolower($_GET["word"],'UTF-8');
  20. }
  21. if(isset($_GET["id"])){
  22. $_id=$_GET["id"];
  23. }
  24. global $PDO;
  25. PDO_Connect("sqlite:"._FILE_DB_PALI_SENTENCE_);
  26. switch($_op){
  27. case "get":
  28. {
  29. $Fetch=array();
  30. if(isset($_word)){
  31. $queryWord = str_replace(" ","",$_word);
  32. $query = "select book,paragraph,text from pali_sent where \"real\" like ".$PDO->quote("%".$queryWord.'%')." limit 0,5";
  33. $Fetch = PDO_FetchAll($query);
  34. $newList = array();
  35. //去掉重复的
  36. foreach($Fetch as $onerow){
  37. $found=false;
  38. foreach($newList as $new){
  39. if($onerow["text"]==$new["text"]){
  40. $found=true;
  41. break;
  42. }
  43. }
  44. if($found==false){
  45. array_push($newList,$onerow);
  46. }
  47. }
  48. $Fetch = $newList;
  49. if(count($Fetch)<5){
  50. $query = "select text from pali_sent where \"real_en\" like ".$PDO->quote('%'.$queryWord.'%')." limit 0,5";
  51. $Fetch2 = PDO_FetchAll($query);
  52. //去掉重复的
  53. foreach($Fetch2 as $onerow){
  54. $found=false;
  55. foreach($Fetch as $oldArray){
  56. if($onerow["word"]==$oldArray["word"]){
  57. $found=true;
  58. break;
  59. }
  60. }
  61. if($found==false){
  62. array_push($Fetch,$onerow);
  63. }
  64. }
  65. }
  66. }
  67. else if(isset($_id)){
  68. }
  69. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  70. break;
  71. }
  72. }
  73. ?>