Finding a string in a file in another language - PHP - UTF-8

I read a lot of posts and tried many things

I have monster files on the game server I'm working on. The game is a Korean game, so many codewords are in Korean style.

I am trying to get a line starting with *아이템 followed by the line I want. I set default_encoding to UTF-8. I can find a string based on other bits, but I want to exclude *아이템 from this output,

sample for code:

 ini_set("max_execution_time", 0); $monsdbconn = sqlsrv_connect("INSTANCE\SQLEXPRESS", array("Database" => "MonsDB", "UID" => "BLAH", "PWD"=> "BLAH")); $monsDir = realpath('C:/PT-Server/GameServer/Monster/'); $monsters = new RecursiveDirectoryIterator($monsDir); if (@$monsdbconn) { $clearit = "DELETE FROM monsdrops"; if (sqlsrv_query($monsdbconn,$clearit)) { foreach($monsters as $name => $object){ $monstername = ""; if (stripos($name, '.inf')){ $monsterfile = file($name); $items = array("WA*", "WP*", "DA*", "WC*"); foreach ($monsterfile as $monster) { if (strstr($monster, "Name")) { //things to remove from the string. $monstrip = array("*Name",'"'); //Remove "" and *Name from the string $monstername = str_replace($monstrip, "", $monster); //Remove spaces from start and end of string to prevent //Duplicate entries, Will not remove space from between words. $monstername = trim($monstername," "); // Space $monstername = trim($monstername," "); // Tab } // THIS IS THE POINT IM SEARCHING FOR ITEMS AT THE MOMENT, BUT I NEED IT TO FIND THE KOREAN CHAR SET if (preg_match("/\D{2}\d{3}/", $monster)) { $string = preg_split("/(\s)/", $monster); foreach ($string as $line) { if ((preg_match("/\D{2}\d{3}/", $line)) && ((stripos($line, "name\\") === false) || stripos($line, ".zhoon") === false)) { $sqlinsert = "INSERT INTO monsdrops ([monstername],[monsterdrops]) VALUES ('$monstername', '$line')"; $insert = sqlsrv_query($monsdbconn, $sqlinsert); if ($insert) { echo "Insert $monstername, $line Successful! <br />"; } else { echo "<br />Insert Failed! <br />"; print_r(sqlsrv_errors()); } } } } } } } } else { echo "Unable To Clear DB"; } } else { echo "Unable to connect to DB"; } @sqlsrv_close($monsdbconn); 

however, he cannot find the characters. If I select another part of the string and repeat it, the characters show (since I set default_encoding), but she cannot find it and it hurts because there are many trigger words in the list that I want to find in Korean

Thanks in advance.

Example file:

 *아이템 5000 ec101 db120 da120 dg120 

ec101 etc. what I'm trying to accomplish.

mb_stripos tried unsuccessfully and tried again with the code below, to no avail. it just does not find the text, however, if I install it to find ec101, it will, but I can not guarantee that it will be in the string, so I used preg_match, but this only works for drops, it will not work for everyone other bits of information I'm trying to find from files

+5
source share
1 answer

stripos() not multibyte. Instead, you should use mb_stripos() , which should work better for you. Also note that you need to explicitly check for a false result. The result of zero can also be interpreted as false.

 $file = "c:\server\monster.inf"; $lines = file($file); foreach ($lines as $line) { // convert to Unicode standard $line = mb_convert_encoding($line, "UTF-8", "EUC-KR"); if (mb_stripos($line, "*아이템") !== false) { echo "$line\n"; } } 
+3
source

Source: https://habr.com/ru/post/1264431/


All Articles