Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialShon Levi
6,036 PointsMultibyte String Functions
Hey, I understand the need of Multibyte String Functions on an app/web but I want to understand now two things:
1 - I tried to work with mb_strlen without define mb_internal_encoding or mb_http_output and it worked great - there are some default values for it? why it worked?
2 - If it has a default values for UTF-8 - why we should use strlen? we can use all the time mb_strlen - if the user will input some problematic characaters it will convert it and if no it will work perfect either? why I need strlen?
1 Answer
Codin - Codesmite
8,600 Pointsstrlen counts bytes and not characters, for example the character ü is infact 2 bytes. It is useful when counting binary strings.
<?php
$str = "Tschüss";
echo strlen($str); // Will output 8 as ü is 2 bytes.
echo mb_strlen($str,'UTF-8'); // Will output 7
?>