Search the Community
Showing results for tags 'http_build_query'.
-
Sorry to have to ask questions again... but I'm having serious hindrance in regards to an assignment. I have to create a Calculator using PHP (which I have completed - see code below), but I have to do this whilst using a query string to provide two numbers and an operator? Moreover, I have to show the URL - showing the following: yourscript.php?n1=5$n2=7&op=m It then says validate that 'n1' and 'n2' are both numbers and that 'op' contains only allowed values???? If everything validates I have to print the result of the equation? My code has two parts and shows two numbers and an operator and prints like this: 5 + 7 = 12. But... I also have to add http_build_query in my code to show the url? <?php require_once 'big.php'; $number1 = 5; $number2 = 7; $operator = "+"; $calculator = new Calculator(); $calculator->setNumbers($number1, $number2); $calculator->setOperator($operator); $calculator->calculate(); echo $number1." ". $operator." ".$number2." = ". $calculator->getOutput(); <?php class Calculator { private $number1, $number2, $operator, $output; public function setNumbers($number1, $number2) { $this->number1 = $number1; $this->number2 = $number2; } public function setOperator($operator) { $this->operator= $operator; } public function calculate() { if($this->operator == "+") $this->output = $this->number1 + $this->number2; elseif($this->operator == "-") $this->output = $this->number1 - $this->number2; elseif($this->operator == "*") $this->output = $this->number1 * $this->number2; elseif($this->operator == "/") $this->output = $this->number1 / $this->number2; else $this->output = "An Error Has Materialize!"; } public function getOutput() { return $this->output; } }
- 4 replies
-
- query string
- http_build_query
-
(and 1 more)
Tagged with: