fork(1) download
  1. <?php
  2.  
  3. try {
  4.  
  5. switch (true) {
  6. case !isset($_POST['mode']):
  7. case !is_string($mode = $_POST['mode']):
  8. throw new Exception('モードが送信されていません', -1);
  9. case $mode === '':
  10. throw new Exception('モードが指定されていません', -2);
  11. case $mode === '1':
  12. $result = 'モード1の処理をしました';
  13. break;
  14. case $mode === '2':
  15. $result = 'モード2の処理をしました';
  16. break;
  17. default:
  18. throw new Exception('モードの値が不正です', -3);
  19. }
  20.  
  21. printf('<span style="color:green">%s</span>', $result);
  22.  
  23. } catch (Exception $e) {
  24.  
  25. printf('<span style="color:red">%s(%d)</span>',
  26. $e->getMessage(),
  27. $e->getCode()
  28. );
  29.  
  30. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<span style="color:red">モードが送信されていません(-1)</span>