All pastes #562965 Raw Edit

Stuff

public text v1 · immutable
·published 2007-06-12 23:42 UTC
rendered paste body
<?php
function natrsort (&$array)
	{
	natsort($array);
	$array = array_reverse($array, true);
	}
function read_file($filename)
	{
	$open = @fopen($filename, 'r');
	$size = @filesize($filename);
	$read = @fread($open, $size);
	@fclose($open);
	return $read;
	}
$blacklist = array( 1 => 'the', , 'be'
, 'to'
, 'of'
, 'and'
, 'a'
, 'in'
, 'that'
, 'have'
, 'I'
, 'it'
, 'for'
, 'not'
, 'on'
, 'with'
, 'he'
, 'as'
, 'you'
, 'do'
, 'at'
, 'this'
, 'but'
, 'his'
, 'by'
, 'from'
, 'they'
, 'we'
, 'say'
, 'her'
, 'she'
, 'or'
, 'an'
, 'will'
, 'my'
, 'one'
, 'all'
, 'would'
, 'there'
, 'their'
, 'what'
, 'so'
, 'up'
, 'out'
, 'if'
, 'about'
, 'who'
, 'get'
, 'which'
, 'go'
, 'me'
, $argv[3])
$file = read_file($argv[1]);
$threshold = $argv[2];
$file = strtolower(preg_replace('/\s/', '___', $file));
$file = preg_replace("/'/", '_', $file);
$file = preg_replace('/\W/', '$1', $file);
$file = str_replace('___', ' ', $file);
$file = str_replace('_', '\'', $file);
$words_array = explode(' ', $file);
$words = array();
foreach ($words_array as $word)
	{
	foreach ($blacklist as $black){
		if ($word == $black)
			break	
	$words[$word]++;
	}
natrsort($words);
foreach ($words as $word => $num)
	{
	if (!($num >= $threshold))
		{
		break;
		}
	if (empty($word))
		{
		continue;
		}
	echo ('"' . $word . '" appears ' . $num . ' times' . "\n");
	}
?>