I have a calculator function that displays the result when a user enters a query in a div (calcanswer) but often the query is not a calculation request, so the result is "query=" in which query represents the user input, and then nothing behind the = sign. I am wondering whether it is possible to implement a function that hides the div when this happens (i.e. there is no calculation).
PHP:
<?php
$a=$_GET['q'];
//$a="1/2";
$add = stripos($a, '+') !== false;
$sub = stripos($a, '-') !== false;
$mul = stripos($a, '*') !== false;
$div = stripos($a, '/') !== false;
if($add){
$b=explode("+",$a);
$n1=(float)$b[0];
$n2=(float)$b[1];
$n3=$n1+$n2;
}else if($sub){
$b=explode("-",$a);
$n1=(float)$b[0];
$n2=(float)$b[1];
$n3=$n1-$n2;
} else if($mul){
$b=explode("*",$a);
$n1=(float)$b[0];
$n2=(float)$b[1];
$n3=$n1*$n2;
} else if($div){
$b=explode("/",$a);
$n1=(float)$b[0];
$n2=(float)$b[1];
$n3=$n1/$n2;
}
?>
HTML:
<div class="calcanswer"><center>
<h4 class="card-title pb-3 mbr-fonts-style display-7">
<?= $a."=".$n3 ?>
</h4></center></div>