Guest User

Untitled

a guest
Feb 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. //the array to chose letters from (possible letters)
  4. $PosLetters = [
  5. 'a','b','v','g','d',
  6. 'đ','e','ž','z','i',
  7. 'j','k','l','lj','m',
  8. 'n','nj','o','p','r',
  9. 's','t','ć','u','f',
  10. 'h','c','č','dž','š'
  11. ];
  12.  
  13.  
  14. //generate 11 letters user can chose from
  15. if (isset($_POST['choose'])) {
  16. for ($i=0; $i < 11; $i++) {
  17. $Rndnumber = mt_rand(0,29);
  18. $Convert = $PosLetters[$Rndnumber];
  19. $Letters[] = $Convert;
  20. }
  21.  
  22. }
  23.  
  24. //function that does the check wether user submited word is in my dictionary
  25. function loadFromfile(){
  26.  
  27.  
  28. if (isset($_POST['submitword'])) {
  29.  
  30. //load all the words from file
  31. $vocab = file('http://localhost/igra_slaganje_reci_php/recnik.txt');
  32.  
  33. //check if user submited word is in the dictionary
  34. if (!empty($_POST['yourword'])) {
  35. $jki = in_array($_POST['yourword'], $vocab);
  36. if ($jki == true) {
  37. echo 'Success';
  38. }else{
  39. echo $_POST['yourword'] . ' doesn't appear in our dictionary.';
  40. }
  41. }
  42. }
  43. }
  44.  
  45.  
  46. ?>
  47.  
  48.  
  49. <!DOCTYPE html>
  50. <html>
  51. <head>
  52. <title></title>
  53. <style type="text/css">
  54. span {
  55. min-width: 50px;
  56. padding: 15px;
  57. margin-right: 15px;
  58. border: 3px solid red;
  59. font-size: 25px;
  60. }
  61. </style>
  62. </head>
  63. <body>
  64. <form method="post">
  65. <input type="submit" name="choose" value="odaberi slovo">
  66. </form>
  67. <div class="letters">
  68. <?php
  69. //put chosen letters each into it's own span
  70. foreach ($Letters as $key => $value) {
  71. echo '<span>' . $value . '</span>';
  72. }
  73. ?>
  74. </div>
  75. <div class="subbmitedword">
  76. <form method="post">
  77. <input type="text" name="yourword">
  78. <input type="submit" name="submitword" value="submit word">
  79. </form>
  80. <?php
  81. loadFromfile();
  82. ?>
  83. </div>
  84. </body>
  85. </html>
Add Comment
Please, Sign In to add comment