Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm strlen() PHP cho độ dài sai ký tự Unicode?

Để lấy độ dài chính xác, dùng mb_strlen() cho ký tự Unicode.

Ví dụ

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

Kết quả

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