I am trying to write a small script to do a dictionary definition lookup for multiple words at a time. Right now, I am my wits end trying to figure out why my very simple script won't work. I am connecting to a local dict server at 192.168.4.4 but that could be replaced with dict.org very easily. The script used to work and returned definitions, but it has stopped doing so, and I haven't upgraded my Apache, or PHP. Any help would be greatly appreciated.
P.S. there is another page with a textarea that feeds $_POST['words']
<?php
if (isset($_POST['words'])) {
$words = trim($_POST['words']);
$words_sep = explode(",", $words);
$socket = fsockopen("192.168.4.4", "2628", $errorno, $errorstr, 90);
$server_send = fgets($socket, 6144);
echo $server_send;
$query = "DEFINE * %s";
$regex_def_num = "^[0-9]{3} ([0-9]+) .+";
$regex_word_info = "^[0-9]{3} \"([^\"]+)\" ([^\" ]+) \"([^\"]+)\"";
for ($i = 0; $i < count($words_sep) ; $i++) {
$format_query = sprintf($query, $words_sep[$i]);
echo $format_query;
if (fputs($socket, $format_query) === false) {
echo "Could not write Command!";
die;
}
$respond = fgets($socket, 6144);
if ($respond === false) {
echo "Error";
die;
}
ereg($regex_def_num, $respond, $reg);
print_r($reg);
$def_num = (int) $reg[1];
for ($j = 0 ; $j < $def_num; $j++) {
$respond = rtrim(fgets($socket, 6144));
if ($respond === false) {
echo "Error";
die;
}
ereg($regex_word_info, $respond, $reg);
$word = $reg[1];
$dictionary = $reg[3];
$definition = "";
while ($current = fgets($socket, 6144)) {
if (ereg("^\.\r\n$",$current)) {
break;
}
$definition .= $current;
}
echo $definition."<br><br>";
}
}
} else {
header("location:index.php");
}
?>