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?
<?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?