Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.91 KB | None | 0 0
  1. <?php  
  2. $current_time = date("H");
  3. $user_age = "18";
  4. $username = "Nikola";
  5. $user_gender = "m";
  6. $time_message = "morning";
  7.  
  8. if ($current_time>0&&$current_time<12)
  9. {
  10.     $time_message = "morning";
  11. }
  12. else
  13.     if ($current_time>=12&&$current_time<18)
  14. {
  15.     $time_message = "day";
  16. }else{
  17.     $time_message = "evening";
  18. }
  19. $user_message = "Good " . $time_message . ", nice";
  20. switch ($user_gender){
  21.     case "m":
  22.         $user_message.=(($user_age<18)?"boy ":"man ");
  23.         break;
  24.     case "f";
  25.         $user_message.=(($user_age<18)?"girl ":"woman ");
  26.         break;
  27.     default;
  28.     break;
  29.     }
  30. echo $username . " welcome to our site" . PHP_EOL;
  31. echo "Your age is," . $user_age . PHP_EOL;
  32. echo "Current time is," . $current_time . "h";
  33.    
  34.  
  35.    
  36. echo "<br>";
  37.  
  38. define("_ADMIN", 2);
  39. define("_USER",1);
  40. $userStatus = 2;
  41. if($userStatus ==_ADMIN)
  42. {
  43.     echo "Admin";
  44. } else if ($userStatus ==_USER) {
  45.         echo "User";
  46.     }
  47.     else
  48.         echo "Nisi nista";
  49.  
  50.  
  51.  
  52. echo "<br>";
  53.  
  54. $user = "Nikola";
  55. $pass = "123";
  56. $validUser = "Nikola2";
  57. $validPass = "123";
  58.  
  59.  
  60. if($user==$validUser && $pass==$validPass){
  61.     echo "Uspesno";
  62. }
  63. else echo "Neuspesno.";
  64.  
  65.  
  66.  
  67. echo "<br>";
  68.  
  69. $status = "2";
  70.  
  71. switch($status)
  72. {
  73.     case 1: echo "Welcome user"; break;
  74.     case 2: echo "Welcome Administrator";break;
  75.     case 3: echo "Welcome SuperAdministrator";break;
  76.     default: echo "Status nije prepoznat";break;
  77.    
  78.    
  79. }
  80. echo "<br>";
  81. $status = "4";
  82. $userMsg = ($status>0&&$status<4)?"Welcome user":"Uknown User";
  83. echo $userMsg;
  84. echo "<br>";
  85. if($status>0&&$status<4)
  86. {
  87.     echo "Welcome User";
  88. } else echo "Uknown User";
  89.  
  90.  
  91. echo "<br>";
  92.  
  93. $x = false;
  94. $a = ((2+3)==5 && (true ==-25) || $x == true);
  95. echo $a;
  96.  
  97.  
  98.  
  99. for($a=1;$a<10;$a++)
  100.     echo "$a<br>";
  101. echo $a;
  102.  
  103.  
  104. echo '<br>';
  105. $x = 10;
  106.     $x = ($x++)-(++$x);
  107.  
  108.     echo $x;
  109.  
  110.  
  111. echo '<br>';
  112. echo '<br>';
  113. echo '<br>';
  114. echo '<br>';
  115.  
  116.  
  117.  
  118. $student = 1;
  119. $profesor = 2;
  120. $koordinator = 4;
  121. $tehnicka_podrska = 8;
  122.  
  123. $loggedUser = 1;
  124. $allowedUser = $koordinator | $tehnicka_podrska;
  125.  
  126. if (($loggedUser&$allowedUser) != 0 )
  127. {
  128.     echo "Allowed user ";
  129.     switch($loggedUser)
  130.     {
  131.         case 1: echo "Student";
  132.         break;
  133.         case 2: echo "Profesor";
  134.         break;
  135.         case 4: echo "Koordinator";
  136.         break;
  137.         case 8: echo "Tehnicka Podrska";
  138.         break;
  139.        
  140.        
  141.     }
  142.    
  143.    
  144. }
  145. $i=0;
  146. for(;;)
  147. {
  148.     echo $i++;
  149.     if($i==5) break;
  150. }
  151.    
  152.  
  153. ?>
  154.  
  155. <select>
  156. <option>Prva1</option>
  157. <option>Prva2</option>
  158. <option>Prva3</option>
  159. <option>Prva4</option>
  160. <option>Prva5</option>
  161. </select>
  162.  
  163. <br>
  164.  
  165. <?php
  166.  
  167.  
  168.  
  169.  
  170.     echo "<br>";
  171.     echo "<select>";
  172.  
  173. $year = date("Y");
  174. for($i=$year;$i>=1960;$i--)
  175. {
  176.    
  177.     $year = date("Y");
  178.     echo "<option>$i</option>";
  179.  
  180. }
  181.     echo "</select>";
  182.     ?>
  183.    
  184.     <?php
  185.     /*
  186.     for($i=1;$i<101;$i++)
  187.         echo $i*$i . "<br>";
  188.    
  189.    
  190.     for($i=1;$i<101;$i++)
  191.         echo pow ($i,2) . "<br>";
  192.    
  193.    
  194.      */
  195.      $suma=0;
  196.      for($i=1;$i<=100;$i++)
  197.      {
  198.          $suma+=$i;
  199.      }
  200.      $broj = $i-1;
  201. echo "Suma prvih $broj brojeva je $suma";    
  202.  
  203. echo "<br>";
  204.  
  205.  
  206.     for($i=1;$i<=10;$i++)
  207.     {  
  208.         for($j=1;$j<=10;$j++)
  209.         {  
  210.                 if($i==1 || $i==10 || $j == 1 || $j == 10) echo "<font color='blue'>X</font>";
  211.                     else if ($i==$j) echo "<font color='red'>D</font>";
  212.                     else if ($i+$j==11) echo "<font color='red'>D</font>";
  213.                 else
  214.                     echo "K";  
  215.         }
  216.         echo "<br>";
  217.     }
  218.     echo "<br>";
  219.    
  220.    
  221.    
  222. $dana = 31;
  223. $meseci = 12;
  224. $godine_start = 1980;
  225. $godine_end = 2000;
  226. echo "<select>";
  227. for($i=1;$i<=$dana;$i++)
  228. {
  229.     echo "<option>".$i."</option>";
  230.    
  231. }
  232. echo "</select>";
  233. echo "<select>";
  234. for($i=1;$i<=$meseci;$i++)
  235. {
  236.     echo "<option>".$i."</option>";
  237.    
  238. }
  239. echo "</select>";
  240. echo "<select>";
  241. for($i=$godine_start;$i<=$godine_end;$i++)
  242. {
  243.     echo "<option>".$i."</option>";
  244.    
  245. }
  246. echo "</select>";
  247.  
  248. echo "<br>";
  249.  
  250.  
  251. $number = 5;
  252. while($number>=2){
  253.     echo $number;
  254.     $number--;
  255.    
  256.    
  257.    
  258. }
  259. echo "<br>";
  260.  
  261. $number=1;
  262. while(true)
  263. {
  264.     while($number<5)
  265.     {
  266.             if($number==3)
  267.             {
  268.                 break(2);
  269.             }
  270.             echo"Number: ".$number."<br>";
  271.             $number++;
  272.     }
  273. }
  274. echo "Program nastavlja";
  275. echo "<br>";
  276.  
  277. for ($i=1;$i<=5;$i++)
  278. {
  279.     if($i==3) continue;
  280.     echo $i;
  281. }
  282. echo "<br>";
  283. echo "<br>";
  284. $i=1;
  285. while($i<=5)
  286. {
  287.     if($i++==3) continue;
  288.     echo $i;
  289. }
  290. echo "<br>";
  291. echo "<br>";
  292. $i=1;$j=1;
  293. while($j<=5)
  294. {
  295.         while($i<=5)
  296.         {
  297.             if($i++==3) continue 2;
  298.             echo $i;
  299.         }
  300.         echo $j++;
  301. }
  302.  
  303.  
  304. echo "<br>";
  305.  
  306. $niz=array(11,2,13,41,55);
  307.  
  308. for($i=0;$i<=5;$i++)
  309.    
  310.     echo $niz[$i]." ";
  311. echo "<br>";
  312.  
  313. foreach($niz as $br)
  314.     echo $br." ";
  315.     echo "<br>";
  316. foreach($niz as $br)
  317. {
  318.     $br = $br*2;
  319.     echo $br. " ";
  320. }
  321.     echo "<br>";
  322. foreach($niz as $br)
  323. echo $br. " ";
  324.  
  325.     echo "<br>";
  326.  
  327.    
  328. $niz=array(11,2,13,41,55);
  329. $suma = 0;
  330. for($i=1;$i<=5;$i++)
  331.     $suma+=$niz[$i];
  332. echo $suma;
  333. echo "<br>";
  334.  
  335.  
  336.  
  337.  
  338.  
  339. $niz=array(11,2,13,41,55);
  340. $max = $niz[0];
  341. for($i=1;$i<count ($niz);$i++)
  342.     if($niz[$i]>$max)
  343.         $max=$niz[$i];
  344.     echo "Max je: ".$max."<br>";
  345.    
  346.    
  347. $niz=array(11,2,13,41,55);
  348. $min = $niz[0];
  349. for($i=1;$i<count ($niz);$i++)
  350.     if($niz[$i]<$min)
  351.         $min=$niz[$i];
  352.     echo "Min je: ".$min."<br>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement