[ create a new paste ] login | about

Link: http://codepad.org/ZQz0Kn3R    [ raw code | output | fork ]

PHP, pasted on Feb 18:
<?php
function processContent($content, $min_count = 2, $exclude_list = array()) {
      	$wordsTmp = explode(' ', str_replace(array('(', ')', '[', ']', '{', '}', "'", '"', ':', ',', '.', '?'), ' ', $content));
      	$words = array();
		$wordsTmp2 = array();
		$omit = array('and', 'or', 'but', 'yet', 'for', 'not', 'so', '&', '&amp;', '+', '=', '-', '*', '/', '^', '_', '\\', '|');
		if(count($exclude_list)>0){
			$omit = array_merge($omit, $exclude_list);
		}
	  	foreach ($wordsTmp as $wordTmp) {
			 $wordTmp = trim(stripslashes($wordTmp));
			 while (substr($wordTmp, strlen($wordTmp) - 1) == ".") {
				$wordTmp = substr($wordTmp, 0, strlen($wordTmp) - 2);
			 }
			 while (substr($wordTmp, 0, 1) == ".") {
				$wordTmp = substr($wordTmp, 1);
			 }
			 $wordTmp = strtolower($wordTmp);
			 $wordsTmp2[] = $wordTmp;
			 if (!empty($wordTmp) && !in_array($wordTmp, $omit) && strlen($wordTmp) >= $min_count) {
				$words[] = $wordTmp;
			 }
		}
		return $words;
}
$word_list = "a
for
of
ok";
$filter_array = explode("\n", $word_list);
print_r($filter_array);
print_r(processContent("of for what k vancha yo", 2, $filter_array));


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Array
(
    [0] => a
    [1] => for
    [2] => of
    [3] => ok
)
Array
(
    [0] => of
    [1] => what
    [2] => vancha
    [3] => yo
)


Create a new paste based on this one


Comments: