SIBERSALDIRI.COM · FOCUSED LESSON
What you will learn
- Explain the relationship between UTF-8 text and Character operation.
- “Why does ü make a difference between the two lengths?” To give a reasoned answer to the question.
- Changing the example and comparing expected and observed behavior.
How it works and where the trust boundary lies
strlen returns the number of bytes, mb_strlen returns the number of characters in the specified encoding. Specify which measure you use when setting limits. Case conversion can affect language conventions; Include examples specifically for I and I. Converting text does not make it safe HTML, SQL or URL; these contexts are treated separately.
Worked example
The following passage makes the concept visible. Evaluate samples containing commands or code in your own separate testing environment, not in the production system. Architectural diagrams and policy examples are not executable programs.
<?php
$text = 'güven';
echo strlen($text), PHP_EOL;
echo mb_strlen($text, 'UTF-8'), PHP_EOL;Expected result and interpretation
In the UTF-8 file, the result is 6 bytes and 5 characters.
Compare the scenarios
| Status | Recommended approach | Why? |
|---|---|---|
| ASCII text | Byte and character can be the same | They are single-byte characters |
| UTF-8 Turkish | Measure separate length | Multi-byte characters are present |
| User search | Test with language samples | I and I can transform differently |
Practice task
Compare the two lengths for ş, İ and blank text; Explain what metric is appropriate for the username limit.
- Write down the expected outcome and acceptance condition before the action.
- Change a single variable; Record the observation and the medium you used.
- Evaluate the result with the comparison table above. Explain which assumption might be wrong if it does not fit.
Common mistake and how to correct it
Do not assume the visible character set and byte size are the same.
Test your understanding
Why does it make a difference between the two lengths?
Answer explained: UTF-8 representation is multiple bytes; Just because it's a single character doesn't mean it's a single byte.
Continue with related lessons
- PHP Data Types: Type Inspection and Input Contracts
- PHP constants: Naming the business rule
- PHP operators: Explicit comparison and precedence
- PHP conditions: From decision table to safe flow
Technical reference
The explanation and examples of this course have been re-prepared for the academy. The link below is a technical reference to verify details of the technology or security approach used.
