You can pull off something like this:
Code: Select all
$x = '714';
print(1+floor(log10($x))); // prints 3
But using a logarithm approach is kinda hairy, you're probably better off with something simple like:
Code: Select all
print(strlen(preg_replace('/\D/','',$x))); // the preg_replace removes all non-digits
Or if you want to ignore anything after the first non-digit (so e.g. "98a7" results in 2 digits, not 3), use:
Code: Select all
print(strlen(preg_replace('/\D.*$/','',$x))); // the preg_replace removes any non-digit and anything beyond
Still, you may wanna consider exactly what do you expect with strings like "0", "000", "00053", "-1", "05.000", "-0001", "0.5", ".5", ".50", "-000.5300", etc
