PHP calculator

There is a "task"

  1. There are two inputs(places where to enter values)
  2. You can enter it there in different number systems
  3. We must define the number systems
  4. Recode the input data into the decimal system
  5. Add them up

This task must be executed in php. (this is all done in the PHP Devel Studio 2.0 program)

There is also an algorithm for "almost ready calculator", but there is an error in it. the algorithm it counts well, but when more than 2 characters appear, T_T{[2] starts to get lost]}

Help please.

$a = c("perA")->text;
if (!preg_match("/^[A-F0-9]+$/",$a)){
        if (!preg_match("/^[A-B0-9]+$/",$a)){
                if (!preg_match("/^[0-9]+$/",$a)){
                        if (!preg_match("/^[0-7]+$/",$a)){
                                if (!preg_match("/^[0-2]+$/",$a)){
                                        if (!preg_match("/^[0-1]+$/",$a)){
                                        }
                                                else {
                                                        $a = base_convert($a,2,10);
                                                }
                                        }
                                        else {
                                                $a = base_convert($a,3,10);
                                        }
                                }
                                else {
                                        $a = base_convert($a,8,10);
                                }
                        }
                        else {
                                $a = $a;
                        }
                }
                else {
                        $a = base_convert($a,12,10);
                }
        }
        else {
                $a = base_convert($a,16,10);
        }

$b = c("perB")->text;
if (!preg_match("/^[A-F0-9]+$/",$b)){
        if (!preg_match("/^[A-B0-9]+$/",$b)){
                if (!preg_match("/^[0-9]+$/",$b)){
                        if (!preg_match("/^[0-7]+$/",$b)){
                                if (!preg_match("/^[0-2]+$/",$b)){
                                        if (!preg_match("/^[0-1]+$/",$b)){
                                        }
                                                else {
                                                        $b = base_convert($b,2,10);
                                                }
                                        }
                                        else {
                                                $b = base_convert($b,3,10);
                                        }
                                }
                                else {
                                        $b = base_convert($b,8,10);
                                }
                        }
                        else {
                                $b = base_convert($b,10,10);
                        }
                }
                else {
                        $b = base_convert($b,12,10);
                }
        }
        else {
                $b = base_convert($b,16,10);
        }

        $convert = ( $a + $b);
    c("ec1")->caption = base_convert($convert,10,2);
    c("ec2")->caption = base_convert($convert,10,3);
    c("ec3")->caption = base_convert($convert,10,4);
    c("ec4")->caption = base_convert($convert,10,5);
    c("ec5")->caption = base_convert($convert,10,8);
    c("ec7")->caption = base_convert($convert,10,12);
    c("ec8")->caption = base_convert($convert,10,16);
    c("ec6")->caption = $convert;
Author: I'm so sorry, 2011-12-17

1 answers

Actually, there is a php GUI, a program called PHP Devel Studio 2.0. When I wrote the code, I thought that working on exceptions, i.e. excluding all possible input options, i.e. 1101, most likely a 2-point number system, but there are too many factors that affect the definition of the number system. But the actual problem from the genus, "is it possible...". But, as they say: "I tried" (c)

 0
Author: venderigross, 2011-12-17 19:18:15