Back to questions
JuniorTheoryCommon
What does the program print?
<?php
$word = 'привет';
echo strlen($word), ' ', mb_strlen($word), ' ';
echo strtoupper($word), ' ', mb_strtoupper($word), "\n";12 6 привет ПРИВЕТ
- Expecting
strlen('привет')to be6:strlencounts bytes, and each Cyrillic letter takes two bytes in UTF-8, so it returns12. - Expecting
strtoupperto capitalize Cyrillic: it changes only the Latin lettersatoz, soприветstays lowercase, whilemb_strtouppergivesПРИВЕТ.
- Why do
strlen('php')andmb_strlen('php')return the same number? - Why can
substr($word, 0, 3)print a broken character?