简体   繁体   中英

PHP MongoDB find with UTF-8

I have a textsearch with MongoDB that i use with PHP.

It works fine except special characters from the german language. eg the word "Törn".

So the characters "Ö", "Ü", "Ä", "ß" can't be found and i don't know why.

This is the json that will be generated for a search:

{"text":"waypoints","search":"T\u00f6rn","language":"de"}

I tried

utf8_encode(utf8_decode($searched));

and

mb_convert_encoding($searched, "UTF-8");

so far but none of them changed the result i get. In $searched the search string, in this case "Törn", will be saved.

This is my command for the textsearch:

$cursor = $this->db->command(array(
    "text" => "waypoints", 
    'search' => $searched,
    'language' => 'de'
));

How can i deal with these characters correctly?

I removed the 'language' => 'de' part of the command, now it's working!

But i'm not able to give a reason why the language parameter chrushed this Query.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM