Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน strlen() ใน PHP ให้ความยาวผิดของตัวอักษร Unicode?

เพื่อรับความยาวที่ถูกต้อง ให้ใช้ mb_strlen() สำหรับตัวอักษร Unicode

โค้ด PHP ดังนี้ -

ตัวอย่าง

<?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); 
?>

ผลลัพธ์

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