
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get String Length Using mb_strlen in PHP
In PHP, multibyte string length (mb_strlen) function is used to get the total string length of a specified string. This function is supported in PHP 4.6.0 or higher versions.
Syntax
int mb_strlen(str $string, str $encoding)
Parameters
mb_strlen() accepts two parameters: $string and $encoding.
$string− It is used to check the string length
$encoding− This parameter is used for character encoding. If it is omitted or null, then the internal character encoding value will be used.
Return Values
mb_strlen() returns the number of characters present in the given string. One is counted as a multi-byte character.
Errors/Exceptions
If the encoding is not known, then it will generate the level E_warning.
Example
<?php // It will return total number of character $result = mb_strlen("Hello World","UTF-8"); echo "Total number of characters: ", $result; ?>
Output
Total number of characters: 11
Note: that it counts the space too in the given string.
Advertisements