Parsephr.php

From Wiki2
Revision as of 19:10, 5 May 2009 by Tim (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
#!/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) {
	echo $phrase;
	$inbo=preg_match('/<b>.*?<\/b>/',$phrase,$matches);
	echo $matches[0]."\n";
	$sections=split("<[/]?b>", $matches[0]);
	$wrd = $sections[1];
	
	//$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
	$thewords = explode(" ", $thedef);//explode it 
	$thewords[0]="";
	$wikidef = implode(" ",$thewords)."\n";//put the string back together
	fwrite($fh, $wikidef);
	echo $wrd . " " . $phrase . " ". $wikidef;
	
}
fclose($fh);
?>