test - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of test.php

  1. <?php
  2. if (isset($_POST['a'])) $string_a = htmlentities($_POST['a']);
  3. if (isset($_POST['b'])) $string_b = htmlentities($_POST['b']);
  4.  
  5. $isEmpty = false;
  6. if ((empty($string_a)) || (empty($string_b))) $isEmpty = true;
  7.  
  8. if (!$isEmpty) {
  9.   $a = (int)$string_a;
  10.   $b = (int)$string_b;
  11.  
  12.   $c = $a + $b;
  13.  
  14.   // Формируем JSON ответ от сервера
  15.   $arr = array('a' => $a, 'b' => $b, 'c' => $c);
  16.   echo json_encode($arr);
  17. }
  18. else {
  19.   echo "error";
  20. }
  21. ?>
File Description
  • test
  • PHP Code
  • 27 Jan-2023
  • 460 Bytes
You can Share it: