Answer the question
In order to leave comments, you need to log in
Problem with ajax + php live search script, misunderstanding with reading from mysql, how to solve?
There is a script for live search, but it works somehow clumsily, it searches in English letters, but doesn’t want to in Russian .... I tried many different settings, but nothing helps, maybe someone has met with such questions and knows the solution where to pick?
It seems that the problem is in a piece of php code
$search_string = preg_replace("/[^A-Za-z0-9А-Яа-я]+$/", "", $_POST['query']);
Answer the question
In order to leave comments, you need to log in
So have you tried it?
// EDIT
Looks like the end-of-line modifier is superfluous.
$strings = [
'foo',
'фУbar',
'бар',
'53252',
'-x-x-x-x-'
];
foreach ($strings as $string) {
var_dump(preg_replace('/[^A-Za-z0-9А-Яа-я]+/u', '', $string));
}
string(3) "foo"
string(7) "фУbar"
string(6) "бар"
string(5) "53252"
string(4) "xxxx"
And if you remove preg_replace does the search work? Maybe an encoding problem? Look with a debugger or output to the log what kind of request to the database is being formed.
I met a similar problem on some site, so they solved it in this way
preg_replace("#[^А-ЯA-Z]#iu", " ", $_POST['query']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question