Function to return number of digits of an integer in PHP
By: Iletras
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
Archived Comments
1. ekukela
View Tutorial By: ekukela at 2017-09-06 14:33:01
2. ebootomuxo
View Tutorial By: ebootomuxo at 2017-09-05 15:06:16
3. epoehoqo
View Tutorial By: epoehoqo at 2017-09-05 14:15:19
4. Lorenton
View Tutorial By: Lorenton at 2017-06-23 10:25:29
5. dcelneqezu
View Tutorial By: dcelneqezu at 2017-01-08 05:07:51
6. ikeboite
View Tutorial By: ikeboite at 2017-01-08 05:01:48
7. enuciluluzi
View Tutorial By: enuciluluzi at 2017-01-08 04:46:18
8. if the number is for exemple 00025478 it return a wrong value :)
View Tutorial By: ahmed at 2015-02-11 12:02:45
9. thanks. it helped a lot!
View Tutorial By: lateforbus at 2013-04-25 03:35:24
10. Thanks.It is very helpful
View Tutorial By: JENI at 2013-03-23 11:01:58
11. Great Thanks
View Tutorial By: anawaz at 2012-10-05 10:28:20
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
PHP convert string to lower case
PHP code to write to a CSV file for Microsoft Applications
PHP code to write to a CSV file from MySQL query
PHP code to import from CSV file to MySQL
Password must include both numeric and alphabetic characters - Magento
Error: Length parameter must be greater than 0
PHP file upload prompts authentication for anonymous users
PHP file upload with IIS on windows XP/2000 etc
Multiple File Upload in PHP using IFRAME
Resume or Pause File Uploads in PHP
Exception in module wampmanager.exe at 000F15A0 in Windows 8