Answer the question
In order to leave comments, you need to log in
Why doesn't in_array work in utf-8?
I came across an incomprehensible behavior of the in_array function. If the scripts are done in win-1251 encoding, everything with Russian letters is in order - the search works. If the script is made in utf-8, the if (in_array($chtoto,$gdeto)) condition does not immediately work. What could be the snag? Or use a string and preg_match instead of an array?
The data is sent for verification using the POST method.
Answer the question
In order to leave comments, you need to log in
> I have both files exclusively in utf-8. The file
encoding has nothing to do with the data being sent.
Only the encoding specified in the HTTP headers matters.
> On the server it is compulsorily exposed utf-8 through htaccess
Nobody ever interests that where it is exposed. What is important is not what is "exposed", but what is actually given away in reality.
You need to look not in htaccess, but in the developer console in the browser, in what encoding the server gives the form.
In the same encoding, the data will be sent back to the server.
> What could be the catch?
No one knows. Fortune telling on coffee grounds is not part of the professional duties of a programmer.
If one string is not equal to the other, then you need to output both of these strings, including non-printable characters, and see what the difference is. For output, you can use the bin2hex function, for example.
The catch is that you don't have everything in utf8. What exactly - dig. First, make sure that $chtoto
the data in and in $gdeto
the same encoding.
As usual, he asked and answered himself. Neither in_array, nor preg_match, nor even mb_eregi are friends with Russian letters in UTF-8. I found only mb_stristr - I will redo the functions for it. In general, well ... with this utf-8!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question