PDA

View Full Version : [PHP] Need help with Multi-Word Definer



Moonbat
06-28-2008, 03:37 PM
Here is the code

<?php

/* If there is POST data */
if (isset($_POST['definetextarea'])) {
/* Getting input and splitting it by word, counting elements in array */
$theunexplodedwords = htmlentities($_POST['definetextarea']);
$theexplodedwords = explode("\n", $theunexplodedwords);
$fatso = count($theexplodedwords);

/* Making a loop to define the words, getting the file contents of dictionary.com */
for ($skinny=0;$skinny<$fatso;$skinny++) {
$url = "http://dictionary.reference.com/browse/$theexplodedwords[$skinny]";
$x = file_get_contents($url);

/* Exploding the stuff before and after the first definition, in order to
isolate the definition, proceeding to echo the definition */
$y = explode("<table class=\"luna-Ent\"><tr><td valign=\"top\" class=\"dn\">*.</td><td valign=\"top\">", $x);
$definition = explode(" </td></tr></table>", $y[*]);
echo "$theexplodedwords[$skinny] - $definition[0] <br>";
}

} else {

/* Echoing the HTML form if no POST data is detected */
echo <<<HTMLONE
<html>
<head><title>Multi-Word Definer</title></head>
<body>
<p align='center'>
Type in one word per line.
<br>
The Multi-Word Definer will define each word.
<br>
The definitions are from <a href="http://dictionary.reference.com/">Dictionary.com</a>.
<form name='defineform' action='$PHP_SELF' method='POST'>
<center><textarea name='definetextarea' rows='*0' cols='20'>Enter words here</textarea></center>
<center><input type='submit' value='Define!'></center>
</form>
</p>
</body>
</html>
HTMLONE;
}
?>
The problem is that I can only define one word, and when I try multiple words it doesn't work correctly. Can anyone help me?

Moonbat
07-08-2008, 11:04 AM
I'm using newlines (\n)

Moonbat
07-12-2008, 01:20 PM
Well, here's some I/O


Input
test

Output
test - the means by which the presence, quality, or genuineness of anything is determined; a means of trial.

----------------------------------------------

Input
test
cheese

Output
test -
cheese - the curd of milk separated from the whey and prepared in many ways as a food.

-----------------------------------------------

Input
test
cheese
(I pressed Enter after 'cheese' leaving this line empty)

Output
test -
cheese -
-