在没有内存异常的阶乘结果中计算0位数

I want to find 0 digits after decimal results of factorial number without using as a string and in bulit functions .

 For e.g.
 Number                     Factoial result         count of 0 occured after nums
   1!                         = 1                                     => 0
   5!                         = 120                                   => 1
   10!                        = 3628800                               => 2
   15!                        = 1307674368000                         => 3

As per last column i want to find out the total count of "0" at last number.Without having memory exception in php.

Thanks in advance

I provide you a function using substr. You can try this

function countLastZero($num){
    $count = 0;
    while(strlen($num) > 0){
        $las = substr($num, -1);
        if($las == 0){
            $count++;
            $num = substr($num, 0, strlen($num) - 1);
        }else{
            break;
        }
    }
    return $count;
}

echo countLastZero(1307674368000); //output 3