Thursday, 2 January 2014

bcmod()

Earlier I mentioned how to fix a problem if you haven't got bcmod installed on your server and you are too idle to install it.  I think it may have been a bit of a bodge.

Below is a better fix from php.net.  Just define the bcmod function on the page above where you need to use it.

function bcmod( $x, $y )
{
    $take = 5;   
    $mod = '';

    do
    {
        $a = (int)$mod.substr( $x, 0, $take );
        $x = substr( $x, $take );
        $mod = $a % $y;  
    }
    while ( strlen($x) );

    return (int)$mod;
}