簡體   English   中英

錯誤strlen函數未正確計算php中的單詞

[英]ERROR strlen function is not count properly of words in php

請幫我。
$ string =“細分”; echo strlen($ string);

Output: 23;

我想輸出Output:11;

我相信您的字符串編碼為UTF-16,strlen將其計算為UTF-8

您的php文件的字符編碼采用UTF-16格式,或者該字符串來自使用UTF-16對其進行編碼的源

使用mb_strlen函數:

echo mb_strlen($string);

您可以在轉換前先轉換變量編碼

$string = "Subdivision";
// $string = mb_convert_encoding($string, "UTF-16"); //just a test and its print 22 as you and user3647971 said
$string = mb_convert_encoding($string, "UTF-8");
echo strlen($string);

暫無
暫無

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

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