簡體   English   中英

Unicode字符在preg_match_all中不起作用

[英]Unicode characters not working in preg_match_all

我正在嘗試查找文件中出現字符串的數量。但是文件中充滿了用Unicode字符編寫的句子。

function probability($next,$now){
            $text_file = file_get_contents("temp/train_set.txt");
            $ans = preg_match_all("/\b$now $next\b/i", $text_file);
            echo $ans."<br>";
}

$ text_file變量找到所有句子並打印unicode句子就好了(我看到了echo)。

$ now$ next是兩個Unicode字符串,例如$ now =“আমি”和$ next =“ভাত”。 然后結果是0 ,但是我的文件中同時包含了兩個字符串。

但是每當我放$ now和$ next兩個英文字符串時。 它為我提供了實際計數。 每當我在$ now和$ next中放入unicode字時,就會出現問題。 我不知道我的問題應該像是“如何使preg_match_all支持孟加拉unicode字符”

問我有沒有問題。

謝謝

使用/u標志(unicode):

$ans = preg_match_all("/\b$now $next\b/ui", $text_file);
//                              here __^

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM