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