strlen() php 函式給出了錯誤的 unicode 字元長度?


為獲取正確長度,請對 Unicode 字元使用 mb_strlen()。

PHP 程式碼如下所示 −

示例

 線上演示

<?php
   $unicodeValues = 'JohnSmȉth';
   echo "The string length with mb_strlen=",mb_strlen($unicodeValues, 'utf8');
   echo "
";    echo "The string length with strlen=",strlen($unicodeValues); ?>

輸出

The string length with mb_strlen=9
The string length with strlen=10

更新於: 2020 年 11 月 20 日

433 人瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.