There is a govnod that was written and it displays the data coming in json here it is:

 var timeout = null; $('#searchword').bind('textchange', function (event, numberkey) { var keyword = $(this).val() //console.log("это1:" + keyword) if(keyword.length > 3 && timeout == null) { $('#loader').show(); timeout = setTimeout( function(){ timeout = null; var keyword1 = $('#searchword').val(); //console.log("это2:" + keyword1) var d = [] $('#search_suggestion_holder li').detach(); $('div.ui-tooltip').detach(); $.ajax({ url:'auto-complete.php', data:'keyword='+keyword1, dataType:'json', error: function(jqXHR, textStatus, errorThrown) { alert('ошибка, F12'); console.log('jqXHR:'); console.log(jqXHR); console.log('статус:'); console.log(textStatus); console.log('ошибка:'); console.log(errorThrown); }, success: function(d){ //console.log($.isEmptyObject(d)); if (!! $.isEmptyObject(d)){ //console.log("1") var nafin = '<li class="hover-img">Ничего не найдено</li>' $("#search_suggestion_holder").html(nafin) $('#search_suggestion_holder').show(); $('#loader').hide(); } else { //console.log("2") $.each(d, function(i, val) { //console.log(val.icon + val.value); //console.log(i); var descrmin = val.descr.substr(0, 150); //console.log(descrmin) var hoverimg = "img-hover=\"<img src=/shop/medium/" + val.icon+"> <br> "+ descrmin + "\"" var resultat = '<li class="hover-img" title ' + hoverimg + '><img src="/shop/32x32/' + val.icon + '">' + val.value + '</li>' //console.log(resultat) $('#loader').hide(); $(resultat).appendTo("#search_suggestion_holder") //console.log($("#search_suggestion_holder").html()); $('#search_suggestion_holder').show(); $(".hover-img").tooltip({ content: function (event, ui) { return $(this).attr('img-hover'); }, track: true, }); }) } } }); },700); } else if(keyword.length < 1){ $('#search_suggestion_holder li').detach(); $('div.ui-tooltip').detach(); $('#search_suggestion_holder').hide(); var newwrite = '<li class="hover-img">начните вводить</li>' //console.log(newwrite) $("#search_suggestion_holder").html(newwrite) $('#search_suggestion_holder').show(); $('#loader').hide(); } else if(1 > keyword.length < 3){ $('#loader').show(); $('#search_suggestion_holder li').detach(); $('div.ui-tooltip').detach(); $('#search_suggestion_holder').hide(); var min3 = '<li class="hover-img">Введите больше 3 символов</li>' //console.log(min3) $("#search_suggestion_holder").html(min3) $('#search_suggestion_holder').show(); $('#loader').hide(); //console.log($("#search_suggestion_holder").html()); } }) 

how to realize that if he was in the water of the йцукен he also looked for qwerty and йцукен , I suppose you need to make an array q = й w = ц and so on, if there are simpler solutions, tell me.

UPDATE

Wrote this function:

 function Auto(str) { replacer = { "q":"й", "w":"ц" , "e":"у" , "r":"к" , "t":"е", "y":"н", "u":"г", "i":"ш", "o":"щ", "p":"з" , "[":"х" , "]":"ъ", "a":"ф", "s":"ы", "d":"в" , "f":"а" , "g":"п" , "h":"р" , "j":"о", "k":"л", "l":"д", ";":"ж" , "'":"э" , "z":"я", "x":"ч", "c":"с", "v":"м", "b":"и", "n":"т" , "m":"ь" , ",":"б" , ".":"ю" , "/":"." }; for(i=0; i < str.length; i++){ if( replacer[ str[i].toLowerCase() ] != undefined){ if(str[i] == str[i].toLowerCase()){ replace = replacer[ str[i].toLowerCase() ]; } else if(str[i] == str[i].toUpperCase()){ replace = replacer[ str[i].toLowerCase() ].toUpperCase(); } str = str.replace(str[i], replace); } } return str; } 

But this option works only in one direction (q ---> й) , as without using a duplicate array d: q to make it work in both directions (q <---> й)(й <---> q)

  • And why qwerty -> ytsuken? There are also other layouts, for example, "yard". But if you need this way, then I do not see any other option except the associated array for transcoding. - Vartlok Nov.
  • You probably did not quite understand, I need that when I entered hfwbz he found a рация , as well as looking for a gopro to search for gopro - Alexey Vasilyev
  • one
    Well, like this? Value qwerty <-> ytsuken, this is only one of the options. There are others, as I have already given an example, this is a courtyard layout. Although if you only need the most popular option, use only it. - Vartlok Nov.
  • @ Alexey Vasilyev, why do you say that you brought this code wrapper? - Dmitriy Simushev
  • I want to go through js and be substituted in keyword1 - Alexey Vasilyev

1 answer 1

I would do it like this, make two arrays, one with the English characters arr.ENG and the other with Russian arr.RUS, then we go to the source line .toLowerCase and split it into an array via .split, then we go around the line stupidly with a loop, and if we find a match with arr.ENG, then we take it and replace it with a symbol from the arr.RUS array, the arrays must match the indices by letter, that is, for example, arr.RUS [8] = "З", and arr.ENG [8] = "Z ". At the output, we glue a string from the array and everything is ready, you can check the source language with a simple RegExp by checking for at least one letter from the required alphabet in the word

  • one
    I looked at my keyboard and I have "Z <-> I", but for some reason you have a "Z", or I did not understand your answer at all. And it is easier to create two objects with mapping, as the author of the question suggests. - Vartlok Nov.
  • and not in php but in js can this be done? - Alexey Vasilyev
  • Vartlok, wrote before dinner, hurried and wrote for transliteration, then yes, it’s necessary "W <-> P", Alexey Vasilyev and I wrote in relation to JS, PHP threw many years ago because of its futility, but this is not the topic of this issue - pnp2000
  • @ vnn198 I ask you for help to cross your idea and my code, is it real? or easier to make a separate function? In general, you need at least an approximate outline, then I think I will understand the principle. - Alexey Vasilyev
  • I would turn in the function , the code is simple, just volumetric - pnp2000