Programming Tutorials

Function to return number of digits of an integer in PHP

By: Iletras in PHP Tutorials on 2011-04-08  

This is a very simple but useful function to return number of digits of an integer.

//function declaration
function count_digit($number) {
return strlen((string) $number);
}
//function call
$num = 12312;
$number_of_digits = count_digit($num); //this is call :)
echo $number_of_digits;
//prints 5





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in PHP )

Integers and Floating-Point Numbers in PHP

Count occurrences of a character in a String in PHP

Comparison operators in PHP

preg_match(), function preg_match_all(), preg_grep() in PHP

Setting up PHP in Windows 2003 Server IIS7, and WinXP 64

Function to convert strings to strict booleans in PHP

Reading word by word from a file in PHP

All possible substrings in a String in PHP

How to fix: Warning: Visiting this site may harm your computer - domainameat.cc

Function to return number of digits of an integer in PHP

Using PEAR::Crypt_HMAC in PHP

PHP convert string to lower case

Cannot load /usr/local/apache/libexec/libphp4.so into server: ld.so.1:......

Running different websites on different versions of PHP in Windows 2003 & IIS6 platform

error: "Service Unavailable" after installing PHP to a Windows XP x64 Pro

Latest Articles (in PHP)