strlen() in PHP — String Length Function
The strlen() function in PHP is used to get the number of characters in a string (including spaces and special characters).
Syntax:
strlen(string $string): int
Examples:
1. Basic Usage:
echo strlen("Hello");
// Output: 5
2. With Spaces:
echo strlen("Hello World");
// Output: 11
3. With Special Characters:
echo strlen("Hi 😊");
// Output: 5 (because emojis may count differently depending on encoding)
4. Empty String:
echo strlen("");
// Output: 0
Note:
strlen()counts bytes, not characters in multibyte strings (like UTF-8 emojis or some foreign languages).- For multibyte-safe length, use
mb_strlen().
0
likes
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
