how to get length of integers in PHP ? how to get length of integers in PHP ? php php

how to get length of integers in PHP ?


$num_length = strlen((string)$num);if($num_length == 10) {    // Pass} else {    // Fail}


if (preg_match('/^\d{10}$/', $string)) {  // pass} else {  // fail}


This will work for almost all cases (except zero) and easily coded in other languages:

$length = ceil(log10(abs($number) + 1)