NBR TEST PARAM - 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 NBR TEST PARAM.php

  1. <?php
  2. // -----------------------------------------------
  3. // Otestování zařazení dne pro vlaky
  4. // 1,2,3,4,5,6,7,X,T
  5. //
  6. // http://sandbox.onlinephpfunctions.com/code/6226a21721c794ac0bc43d7ffd204f4369f29f6a
  7. // -----------------------------------------------
  8. function nbr_test_param($atts, $timestamp = null){
  9.     nastav_casovou_zonu();
  10.     $out = false;
  11.     if(!$timestamp){$timestamp = time();}
  12.  
  13.     $svatky = array("5.7.2019", "6.7.2019", "28.9.2019", "28.10.2019", "17.11.2019", "24.12.2019", "25.12.2019", "26.12.2019", "1.1.2020", "10.4.2020", "13.4.2020", "1.5.2020", "8.5.2020");
  14.  
  15.     $dayofweek = (date("w", $timestamp) == 0) ? 7 : date("w", $timestamp);
  16.  
  17.     if(($atts >= 1 && $atts <= 7) && $dayofweek == $atts){
  18.         $out = true;
  19.     } elseif($atts == "X" && $dayofweek >= 1 && $dayofweek <= 5){
  20.         $out = true;
  21.     } elseif($atts == "T" && ($dayofweek == 7) || in_array(date("j.n.Y", $timestamp), $svatky)){
  22.         $out = true;
  23.     } elseif($atts == "S" && in_array(date("j.n.Y", $timestamp), $svatky)){
  24.         $out = true;
  25.     }
  26.     
  27.     $out = date("d.m.Y");
  28.     
  29.     return $out;
  30. }
  31.  
  32. function nastav_casovou_zonu($defaultTimeZone = 'UTC'){
  33.     if (date_default_timezone_get() != $defaultTimeZone) {
  34.         date_default_timezone_set($defaultTimeZone);
  35.     }
  36. }
  37.  
  38.  
  39.  
  40. echo nbr_test_param("X");
  41. ?>
File Description
  • NBR TEST PARAM
  • PHP Code
  • 08 Aug-2019
  • 1.29 Kb
You can Share it: