Here's a much simpler alternative for the largest common dividers:
function ratio( $x, $y ){ $gcd = gmp_strval(gmp_gcd($x, $y)); return ($x/$gcd).':'.($y/$gcd); }
Request echo ratio(25,5); returns 5:1 .
If your server has not been compiled with GMP functions ...
function gcd( $a, $b ){ return ($a % $b) ? gcd($b,$a % $b) : $b; } function ratio( $x, $y ){ $gcd = gcd($x, $y); return ($x/$gcd).':'.($y/$gcd); }
source share