Hướng dẫn case-insensitive search in php - tìm kiếm không phân biệt chữ hoa chữ thường trong php

Tôi đang sử dụng jQuery autocompleter để tìm kiếm.

Từ mã dưới đây của tôi, tìm kiếm của tôi chỉ xảy ra trên trường hợp nhạy cảm, tôi muốn làm cho trường hợp tìm kiếm không nhạy cảm. ví dụ. $array={the king, The king, The man}

Và từ khóa tìm kiếm của tôi là "The" thì hiện tại tôi chỉ nhận được đầu ra như {The king, The man} Tôi không nhận được the king vì nó ở trường hợp thường xuyên.

Điều tôi muốn là, nếu tôi viết "The" thì tôi sẽ nhận được cả ba kết quả.

Xin hãy giúp tôi giải quyết vấn đề của tôi

view.php


$[document].ready[function[] {
        $[function[] {
                $[ "#autocomplete" ].autocomplete[{


                        source: function[request, response] {

                     $.ajax[{ url: "",
                                data: { term: $["#autocomplete"].val[]},
                                dataType: "json",
                                type: "POST",
                                success: function[data]{

                                        response[data];
                                }
                        }];
                },

                minLength: 3,
                select: function [a, b] {
    $[this].val[b.item.value];
    $[".searchform1"].submit[]
}
                }];
        }];
        $['#autocomplete'].focus[]; 
}];


  function monkeyPatchAutocomplete[] {

      // Don't really need to save the old fn, 
      // but I could chain if I wanted to
      var oldFn = $.ui.autocomplete.prototype._renderItem;

      $.ui.autocomplete.prototype._renderItem = function[ ul, item] {
          var re = new RegExp["^" + this.term, "i"] ;
          var t = item.label.replace[re,"" + this.term + ""];
          return $[ "
  • " ] .data[ "item.autocomplete", item ] .append[ "" + t + "" ] .appendTo[ ul ]; }; } $[document].ready[function[] { monkeyPatchAutocomplete[]; $["#input1"].autocomplete[{ // The source option can be an array of terms. In this case, if // the typed characters appear in any position in a term, then the // term is included in the autocomplete list. // The source option can also be a function that performs the search, // and calls a response function with the matched entries. source: function[req, responseFn] { addMessage["search on: '" + req.term + "'
    "]; var re = $.ui.autocomplete.escapeRegex[req.term]; var matcher = new RegExp[ "^" + re, "i" ]; var a = $.grep[ wordlist, function[item,index]{ //addMessage["  sniffing: '" + item + "'
    "]; return matcher.test[item]; }]; addMessage["Result: " + a.length + " items
    "]; responseFn[ a ]; }, select: function[value, data]{ if [typeof data == "undefined"] { addMessage['You selected: ' + value + "
    "]; }else { addMessage['You selected: ' + data.item.value + "
    "]; } } }]; }]; --------------- ---------------

    Bài Viết Liên Quan

    Chủ Đề