Parsephr.php

From Wiki2
#!/usr/bin/php -w
<?
//$fname = $argv[1];//still working to make this run from command line args
$fname = '4bip/v/leasingtherain.txt';
$lines = file($fname)or die("yo can't open file \n");
$outFile = "4bip/v/Vocabltr.txt";
$fh = fopen($outFile, 'w') or die("can't open file");
// Loop through $lines array, lookup meta description tag for def of each $wrd.
foreach ($lines as $line_num => $phrase) {
	$phrase=preg_replace( '/\r\n/', '', substr(trim($phrase),1) );//get rid of the line return
	$inbo=preg_match('/<b>.*?<\/b>/',$phrase,$matches);//get what in bold tags
	$sections=split("<[/]?b>", $matches[0]);//split before/in/after bold tag
	$wrd = $sections[1];//gets you whats between tags
	$tags = get_meta_tags('http://www.answers.com/'.$wrd);//go out on internet
	$thedef = $tags['description']."\n";//pick out the description tag and keep the string
	$thewords = explode(" ", $thedef);//explode it 
	$thewords[0]="";//get rid of the first word(the defined word)
	$defphrase = implode(" ",$thewords)."\n";//put the string back together w/o it
	//ex: $phrase="n. , pl. -ties . The state or quality of being modern";
	$inbo=preg_match('/(^.*?)[A-Z]/',$defphrase,$matches);//everything uptoincl first capital
	$string = $matches[0]."\n";
	$pos = trim(substr($string, 0, -2));//get rid of last character
	$isdef=preg_match('/[A-Z].*/',$defphrase,$justdef);
	$def = $justdef[0];
	$def=preg_replace( '/\r\n/', '', trim($def) );//get rid of the line return
	$defstr = ";".$wrd . ": ''" . $pos ."'' ". $def . ": ''" . $phrase ."''\n";
	echo $defstr;
	fwrite($fh, $defstr);
	
}