J B Wock - by Tisselli, Eugenio
<?
function getSynonym($word) { //this function gets a synonym from a synonyms server
$synonym = "";
$thesaurus="http://thesaurus.reference.com/search?q=$word";
$fd = fopen($thesaurus,"r");
while(!feof($fd)) {
stream_set_timeout($fd, 20);
$pgdata .= fread($fd, 5000) or die("i'm getting tired, please hit the refresh button ...");
}
fclose($fd);
$start = strpos($pgdata, "Synonyms:");
$end = strpos($pgdata, "Source:");
$size= $end-$start;
$synonym = strip_tags(substr($pgdata, $start, $size));
$synonym = ereg_replace ("Synonyms:", "", $synonym);
$words = explode(",",$synonym);
if (sizeof($words)>0) {
$synonym = $words[rand(0,sizeof($words)-1)];
} else {
$synonym = "";
}
if (strpos($synonym,"Antonyms:") > 0) {
$synonym = "";
}
return $synonym;
}
function storeInDatabase($phrase,$rightnow,$db) {
//this function stores the new frase in jb wock's database
}
$publish = rand(0,1); //is jbwock going to publish?? 0 means yes, 1 means not today...
if ($publish == 0) {
$db=mysql_connect ("localhost", "xxxx", "xxxx");
mysql_select_db ("xxxx"); // connect to jbwock's database
$fd = fopen("http://img.tfd.com/daily/quote-top.js","r"); //open the daily quotes page...
while(!feof($fd)) {
stream_set_timeout($fd, 20);
$pgdata .= fread($fd, 5000);
}
fclose($fd);
$iniphrase = strpos($pgdata,"<SPAN>")+6; //extract the original phrase from the javascript code
$endphrase = strpos($pgdata,".",$iniphrase);
$lenphrase = $endphrase - $iniphrase;
$phrase = trim(substr($pgdata,$iniphrase,$lenphrase)).".";
if ($phrase != "") { //go ahead if there is something to say...
$times = rand(0,2); //number of times the original phrase is going to be twisted
for($r=0;$r<=$times;$r++) {
$words = explode(" ",$phrase); //separate individual words...
for ($i=0; $i<sizeof($words); $i++) {
$words[$i] = stripslashes($words[$i]);
if ((strlen($words[$i]) > 2) && ($words[$i] != "for") && ($words[$i] != "the") && ($words[$i] != "and") && ($words[$i] != "but") && ($words[$i] != "from") && ($words[$i] != "with") && ($words[$i] != "had") && ($words[$i] != "was") && ($words[$i] != "out") && ($words[$i] != "not") && ($words[$i] != "may") && ($words[$i] != "has") && ($words[$i] != "let") && ($words[$i] != "yet") && ($words[$i] != "more") && ($words[$i] != "into") && ($words[$i] != "over") && ($words[$i] != "his") && ($words[$i] != "her") && ($words[$i] != "its" && (strtolower($words[$i]) != "bush"))) {
$synonym = trim(getSynonym($words[$i])); //find synonym for current word
if ($synonym != "") {
$words[$i] = eregi_replace(" ","",$synonym);
}
}
}
$phrase = ucfirst(implode(" ",$words));
}
$phrase = str_replace("*","",$phrase); //sometimes an '*' will fly into the house...
$phrase = urlencode(trim($phrase)); //pack it, get it ready...
$rightnow = date("Y-m-d");
storeInDatabase($phrase,$rightnow,$db);
}
}
?>
Barcelona, 2006
|