在不同语言的文件中搜索字符串 - PHP - UTF-8

Cra*_*g B 5 php utf-8

我已阅读了很多帖子并尝试过很多东西,

我在游戏服务器上有一些怪物文件,游戏是一个韩国游戏所以很多代码词都在韩国.

我试图得到一个开头的行,*???然后是我想要的字符串.我将default_encoding设置为UTF-8.我能够根据其中的其他位找到字符串,但我想*???从输出中排除它,

代码的示例是:

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);
Run Code Online (Sandbox Code Playgroud)

然而,它找不到字符,如果我选择该行的另一部分并回显它,字符显示(因为我设置了default_encoding)但它找不到它,并且它很痛苦,因为列表中有许多触发词我希望找到那些在韩国.

提前致谢.

该文件的示例如下:

*??? 5000 ec101 db120 da120 dg120 
Run Code Online (Sandbox Code Playgroud)

ec101等是我试图偷窃的东西.

尝试了mb_stripos失败,并再次尝试使用下面提供的代码无济于事.它只是没有找到文本,但是如果我设置它找到ec101它会,但我不能保证将在行中所以我使用preg_match,但只适用于滴,它不适用于所有我试图从文件中找到的其他信息

mik*_*n32 3

stripos()不兼容多字节。相反,你应该使用mb_stripos()哪个更适合您。另请注意,您需要明确检查错误结果。结果为零也可以被解释为假。

\n\n
$file = "c:\\server\\monster.inf";\n$lines = file($file);\nforeach ($lines as $line) {\n    // convert to Unicode standard\n    $line = mb_convert_encoding($line, "UTF-8", "EUC-KR");\n    if (mb_stripos($line, "*\xec\x95\x84\xec\x9d\xb4\xed\x85\x9c") !== false) {\n        echo "$line\\n";\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n