f.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. $ajax = isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
  3. strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
  4. $req_term = isset($_REQUEST['term']) ? $_REQUEST['term'] : '';
  5. if (!$ajax) {
  6. ?>
  7. <!DOCTYPE HTML>
  8. <html lang="en">
  9. <head>
  10. <meta charset="utf-8">
  11. <title>The Devil's Dictionary by Ambrose Bierce</title>
  12. <link rel="stylesheet" href="06.css">
  13. </head>
  14. <body>
  15. <div id="container">
  16. <div id="header">
  17. <h2>The Devil's Dictionary</h2>
  18. <div class="author">by Ambrose Bierce</div>
  19. </div>
  20. <form action="f.php">
  21. <input type="text" name="term" value="<?= $req_term; ?>" id="term" />
  22. <button type="submit">Search</button>
  23. </form>
  24. <?php
  25. }
  26. $entries = array(
  27. 'FAITH' => array(
  28. 'part' => 'n.',
  29. 'definition' => 'Belief without evidence in what is told by one who speaks without knowledge, of things without parallel.',
  30. ),
  31. 'FAMOUS' => array(
  32. 'part' => 'adj.',
  33. 'definition' => 'Conspicuously miserable.',
  34. 'quote' => array(
  35. 'Done to a turn on the iron, behold',
  36. 'Him who to be famous aspired.',
  37. 'Content? Well, his grill has a plating of gold,',
  38. 'And his twistings are greatly admired.',
  39. ),
  40. 'author' => 'Hassan Brubuddy',
  41. ),
  42. 'FELON' => array(
  43. 'part' => 'n.',
  44. 'definition' => 'A person of greater enterprise than discretion, who in embracing an opportunity has formed an unfortunate attachment.',
  45. ),
  46. 'FIDDLE' => array(
  47. 'part' => 'n.',
  48. 'definition' => 'An instrument to tickle human ears by friction of a horse\'s tail on the entrails of a cat.',
  49. 'quote' => array(
  50. 'To Rome said Nero: "If to smoke you turn',
  51. 'I shall not cease to fiddle while you burn."',
  52. 'To Nero Rome replied: "Pray do your worst,',
  53. '\'Tis my excuse that you were fiddling first."',
  54. ),
  55. 'author' => 'Orm Pludge',
  56. ),
  57. 'FIDELITY' => array(
  58. 'part' => 'n.',
  59. 'definition' => 'A virtue peculiar to those who are about to be betrayed.',
  60. ),
  61. 'FLOP' => array(
  62. 'part' => 'v.',
  63. 'definition' => 'Suddenly to change one\'s opinions and go over to another party. The most notable flop on record was that of Saul of Tarsus, who has been severely criticised as a turn-coat by some of our partisan journals.',
  64. ),
  65. 'FORCE' => array(
  66. 'part' => 'n.',
  67. 'definition' => '',
  68. 'quote' => array(
  69. '"Force is but might," the teacher said &mdash;',
  70. '"That definition\'s just."',
  71. 'The boy said naught but thought instead,',
  72. 'Remembering his pounded head:',
  73. '"Force is not might but must!"',
  74. ),
  75. ),
  76. 'FORGETFULNESS' => array(
  77. 'part' => 'n.',
  78. 'definition' => 'A gift of God bestowed upon doctors in compensation for their destitution of conscience.',
  79. ),
  80. 'FRIENDLESS' => array(
  81. 'part' => 'adj.',
  82. 'definition' => 'Having no favors to bestow. Destitute of fortune. Addicted to utterance of truth and common sense.',
  83. ),
  84. 'FRIENDSHIP' => array(
  85. 'part' => 'n.',
  86. 'definition' => 'A ship big enough to carry two in fair weather, but only one in foul.',
  87. 'quote' => array(
  88. 'The sea was calm and the sky was blue;',
  89. 'Merrily, merrily sailed we two.',
  90. '(High barometer maketh glad.)',
  91. 'On the tipsy ship, with a dreadful shout,',
  92. 'The tempest descended and we fell out.',
  93. '(O the walking is nasty bad!)',
  94. ),
  95. 'author' => 'Armit Huff Bettle',
  96. ),
  97. 'FUTURE' => array(
  98. 'part' => 'n.',
  99. 'definition' => 'That period of time in which our affairs prosper, our friends are true and our happiness is assured.',
  100. ),
  101. );
  102. $output = array();
  103. foreach ($entries as $term => $entry) {
  104. if (strpos($term, strtoupper($_REQUEST['term'])) !== FALSE) {
  105. $output[] = build_entry($term, $entry);
  106. }
  107. }
  108. if (!empty($output)) {
  109. echo implode("\n", $output);
  110. } else {
  111. echo '<div class="entry">Sorry, no entries found for ';
  112. echo '<strong>' . $_REQUEST['term'] . '</strong>.';
  113. echo '</div>';
  114. }
  115. function build_entry($term, $entry) {
  116. $html = '<div class="entry">';
  117. $html .= '<h3 class="term">';
  118. $html .= $term;
  119. $html .= '</h3>';
  120. $html .= '<div class="part">';
  121. $html .= $entry['part'];
  122. $html .= '</div>';
  123. $html .= '<div class="definition">';
  124. $html .= $entry['definition'];
  125. if (isset($entry['quote'])) {
  126. foreach ($entry['quote'] as $line) {
  127. $html .= '<div class="quote-line">'. $line .'</div>';
  128. }
  129. if (isset($entry['author'])) {
  130. $html .= '<div class="quote-author">'.
  131. $entry['author'] .'</div>';
  132. }
  133. }
  134. $html .= '</div>';
  135. $html .= '</div>';
  136. return $html;
  137. }
  138. if (!$ajax) {
  139. ?>
  140. </div>
  141. </body>
  142. </html>
  143. <?php } ?>