コピー

        <?php
           $url ="https://api.nsktv.work/v1/calc.php?a=6&b=23";
 
           // APIをリクエスト
           error_reporting(0);
           try {
             $result = simplexml_load_file($url);
           } catch (Exception $e) {
             error_reporting(E_ALL);
             return(0);
           } 
           error_reporting(E_ALL);
 
           if(isset($result->Error)){ 
           // エラー表示
           echo $result->Error;
           } else {
           // 計算結果を表示
           if(isset($result->Addition)){ 
             echo "加算(和):".$result->Addition."<br>\n";
             }
           if(isset($result->Subtraction)){ 
             echo "減算(差):".$result->Subtraction."<br>\n";
             }
           if(isset($result->Multiplication)){ 
             echo "乗算(積):".$result->Multiplication."<br>\n";
             }
           if(isset($result->Division)){ 
             echo "除算(商):".$result->Division."<br>\n";
             }
           if(isset($result->Percent)){ 
             echo "(余り:".$result->Percent.")<br>\n";
             }
           }
         ?>