PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Something wrong in your formula spec here, you say $av should be '28' (and I assume match $check), you created $av on the last 3 characters of cs3 which would be 328
Concatenation is done with dot (.), makes litttle sense to put a bunch of vars by themselves inside double quotes..
substr('32328',3) returns '28'. The syntax is:
string substr ( string string, int start [, int length] )
so he is getting the correct results for $av. The problem is in $av2. What should be done is
Modulus division (ex: 9%5) seems to choke when you get to anything greater than 2100000000. So 2100000000%97 will work, but 2200000000%97 will not. I have no clue as to why this is.
However, integer division (ex: 9/5) will work at higher numbers. One way to work around the modulus problem is to do something like the following:
<?php
$test_val=3614000323; // initial value (from $verifstruc)
$div=97; // divisor
$res=$test_val/$div; //result
$res_int=settype($res, "integer"); //type-cast to integer (gets rid of decimal point)
$dec=$res-$res_int; // get the stuff beyond the decimal point (0.2887)
$fin=$div*$dec; // multiply the decimal stuff and the divisor
$end=$round($fin,0); // round to the nearest integer
?>
This does give the correct value ( 28 ), but it is very ugly.
Last edited by daven on Wed Mar 05, 2003 8:47 am, edited 1 time in total.
Slight edit to the previous function I posted. I was thinking in a hard-typed style. The settype() call will not produce the desired results in PHP. Use floor() instead. This could stand to be cleaned up a bit, but it works.