PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

bcmul> <bcdiv
Last updated: Fri, 03 Oct 2008

view this page in

bcmod

(PHP 4, PHP 5)

bcmodRetourne le reste d'une division entre nombres de grande taille

Description

string bcmod ( string $left_operand , string $modulus )

Retourne le reste de la division entre left_operand en utilisant modulus .

Liste de paramètres

left_operand

L'opérande de gauche, sous la forme d'une chaîne de caractères.

modulus

Le modulo, sous la forme d'une chaîne de caractères.

Valeurs de retour

Retourne le modulo, sous la forme d'une chaîne de caractères, ou NULL si modulus vaut 0.

Exemples

Exemple #1 Exemple avec bcmod()

<?php
echo bcmod('4''2'); // 0
echo bcmod('2''4'); // 2
?>

Voir aussi



bcmul> <bcdiv
Last updated: Fri, 03 Oct 2008
 
add a note add a note User Contributed Notes
bcmod
mcuelenaere at gmail dot com
21-Dec-2007 10:00
Heres an useful IBAN generate function:

<?php
function controleer_iban($iban) {
   
$iban = str_replace(array(" ", "  ", "   ", "\t"), "", $iban);
   
$iban = strtoupper(str_replace(" ", "", $iban));
    if(
strlen($iban)>34)
        return
false;
   
$acceptabel = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9 0";
   
$acceptabel = explode(" ", $acceptabel);
    for(
$i = 0; $i<strlen($iban); $i++) {
        if(
in_array(substr($iban, $i, 1), $acceptabel) === false)
            return
false;
    }
   
$alfa = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z";
   
$alfa = explode(" ", $alfa);
    for(
$i = 1; $i<27; $i++) {
       
$alfa_replace[] = $i+9;
    }
   
$controlegetal = str_replace($alfa, $alfa_replace, substr($iban, 4, strlen($iban)-4).substr($iban, 0, 2)."00");
   
$controlegetal = 98 - (int)bcmod($controlegetal,97);
    if((int)
$controlegetal === (int)substr($iban, 2, 2))
        return
true;
    else
        return
false;   
}
?>
sebas at stageprikbord dot nl
27-Mar-2007 04:53
function bc_is_even($int_str) {
  return (int)!($int_str & 1);
}

More resource efficient version of 'bc_is_even'.
jmullan at visi dot com
25-Jul-2006 12:12
<?php
function bc_is_even($int_str) {
    if (
0 < strlen($int_str)) {
        return !((
substr($int_str, -1)) % 2);
    } else {
       
// error                                                                                               
       
return 0;
    }
}
?>
cristianDOTzuddas]NOSPAM[gmailDOTcom
24-Jul-2005 12:45
BC Math is really cool, but has only 10 functions. So we MUST write other BC functions and share the code.

Here is a simple even/odd number check.

<?
function bc_is_even($int_str) {
    if (
strlen($int_str)>0) {
        if (
bcmod($int_str, 2)==='0')
            return
true;
        else
            return
false;
    }
    else       
// error
       
return 0;
}
?>
lauris at night dot lt
23-Dec-2003 05:04
<?php
/**
 * my_bcmod - get modulus (substitute for bcmod)
 * string my_bcmod ( string left_operand, int modulus )
 * left_operand can be really big, but be carefull with modulus :(
 * by Andrius Baranauskas and Laurynas Butkus :) Vilnius, Lithuania
 **/
function my_bcmod( $x, $y )
{
   
// how many numbers to take at once? carefull not to exceed (int)
   
$take = 5;    
   
$mod = '';

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

    return (int)
$mod;
}

// example
echo my_bcmod( "7044060001970316212900", 150 );
?>

bcmul> <bcdiv
Last updated: Fri, 03 Oct 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites