Difference between revisions of "Parsephr.php"

From Wiki2
(New page: <pre> #!/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...)
 
 
Line 9: Line 9:
// Loop through $lines array, lookup meta description tag for def of each $wrd.
// Loop through $lines array, lookup meta description tag for def of each $wrd.
foreach ($lines as $line_num => $phrase) {
foreach ($lines as $line_num => $phrase) {
echo $phrase;
$phrase=preg_replace( '/\r\n/', '', substr(trim($phrase),1) );//get rid of the line return
$inbo=preg_match('/<b>.*?<\/b>/',$phrase,$matches);
$inbo=preg_match('/<b>.*?<\/b>/',$phrase,$matches);//get what in bold tags
echo $matches[0]."\n";
$sections=split("<[/]?b>", $matches[0]);//split before/in/after bold tag
$sections=split("<[/]?b>", $matches[0]);
$wrd = $sections[1];//gets you whats between tags
$wrd = $sections[1];
$tags = get_meta_tags('http://www.answers.com/'.$wrd);//go out on internet
//$wrd=preg_replace( '/\r\n/', '', trim($wrd) );//get rid of the line return
$tags = get_meta_tags('http://www.answers.com/'.$wrd);
$thedef = $tags['description']."\n";//pick out the description tag and keep the string
$thedef = $tags['description']."\n";//pick out the description tag and keep the string
$thewords = explode(" ", $thedef);//explode it  
$thewords = explode(" ", $thedef);//explode it  
$thewords[0]="";
$thewords[0]="";//get rid of the first word(the defined word)
$wikidef = implode(" ",$thewords)."\n";//put the string back together
$defphrase = implode(" ",$thewords)."\n";//put the string back together w/o it
fwrite($fh, $wikidef);
//ex: $phrase="n. , pl. -ties . The state or quality of being modern";
echo $wrd . " " . $phrase . " ". $wikidef;
$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);
}
}
fclose($fh);
?>
</pre>
</pre>

Latest revision as of 21:39, 5 May 2009

#!/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);
	
}