How to use strlen() Function In PHP
The strlen() function returns the length of a given string. It takes a string as a parameter and returns it’s length. It calculates the length of the string including all the whitespaces and special characters.
Syntax:
strlen( $string );
Example:
PHP
<?php $numStr1 = '110010' ; $digitCount1 = strlen ( $numStr1 ); echo "String Length: " . $digitCount1 ; $number = 12345; $numStr2 = (string) $number ; $digitCount2 = strlen ( $numStr2 ); echo "\nString Length: " . $digitCount2 ; ?> |
Output
String Length: 6 String Length: 5
PHP Program to Count Digits of a Number
In this article, we will see how to count the digits of a number in PHP. There are three methods to count digits of a number, these are:
Table of Content
- Using strlen() Function
- Using while Loop
- Using str_split() Function
Contact Us