another to the despotism of himself.', 'quote' => array('He was a slave: at word he went and came;', 'His iron collar cut him to the bone.', 'Then Liberty erased his owner\'s name,', 'Tightened the rivets and inscribed his own.'), 'author' => 'G.J.'), 'EMOTION' => array('part' => 'n.', 'definition' => 'A prostrating disease caused by a determination of the heart to the head. It is sometimes accompanied by a copious discharge of hydrated chloride of sodium from the eyes.'), 'ENVELOPE' => array('part' => 'n.', 'definition' => 'The coffin of a document; the scabbard of a bill; the husk of a remittance; the bed-gown of a love-letter.'), 'ENVY' => array('part' => 'n.', 'definition' => 'Emulation adapted to the meanest capacity.'), 'EPITAPH' => array('part' => 'n.', 'definition' => 'An inscription on a tomb, showing that virtues acquired by death have a retroactive effect. Following is a touching example:', 'quote' => array('Here lie the bones of Parson Platt,', 'Wise, pious, humble and all that,', 'Who showed us life as all should live it;', 'Let that be said — and God forgive it!')), 'EVANGELIST' => array('part' => 'n.', 'definition' => 'A bearer of good tidings, particularly (in a religious sense) such as assure us of our own salvation and the damnation of our neighbors.')); if (isset($entries[strtoupper($_REQUEST['term'])])) { //strtoupper把字符串转化为大写 $term = strtoupper($_REQUEST['term']); $entry = $entries[$term]; echo build_entry($term, $entry); } else { echo '<div>对不起,您找的词不存在</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'])) {
<form action="f.php"> <input type="text" name="term" value="<?php $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) { //strposstrpos(s1,s2) 函数返回字符串s2在字符串s1中第一次出现的位置。如果没有找到该字符串,则返回 false。 if (strpos($term, strtoupper($_REQUEST['term'])) !== FALSE) { $output[] = build_entry($term, $entry); } } if (!empty($output)) { //implode(separator,array)把数组元素组合为一个字符串。separator为可选 echo implode("\n", $output); } else { echo '<div class="entry">对不起,没有找到'; echo '<strong>' . $_REQUEST['term'] . '</strong>'; echo '</div>'; } function build_entry($term, $entry) { $html = '<div class="entry">'; $html .= '<h3 class="term">'; $html .= $term;