Moving the UnitTest directory out of the docs/ folder and into the root of the framework
[isso.git] / tools / wordrunner.php
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 <head>
5 <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
6 <title>WordRunner</title>
7 </head>
8 <body>
9
10 <?php
11 // SVN: $Id$
12
13 error_reporting(E_ALL & ~E_NOTICE);
14
15 // ### END HTML ######################################################
16
17 if (empty($_POST['do']))
18 {
19 // ### START HTML ####################################################
20 ?>
21
22 <h1>Welcome to WordRunner</h1>
23 <p>This script will count the number of times a word is used in a passage. Simply copy and paste your article into the text area below and press "Run Words" to start the process.</p>
24
25 <?php
26 // ### END HTML ######################################################
27 }
28 else
29 {
30
31 // ### START HTML ####################################################
32 ?>
33
34 <h1>Document Word Run Complete</h1>
35 <p>WordRunner has finished processing your document: the results are listed below.</p>
36
37 <table cellpadding="4" cellspacing="2" border="1">
38 <tr style="background-color:#696969">
39 <td><strong>Word</strong></td>
40 <td><strong>Usage Index</strong></td>
41 </tr>
42
43 <?php
44 // ### END HTML ######################################################
45 $wordrunner_text = htmlspecialchars($_POST['wordtext']);
46
47 $punctstrip = str_replace(array('&quot;', '"', '\'', '&', '/', '.', ',', '!', '@', ';', ':', '[', ']', '(', ')'), '', $wordrunner_text);
48 $wordarray = preg_split('#[\s]+#', $punctstrip);
49
50 foreach ($wordarray AS $word)
51 {
52 if (!is_int($word) AND trim($word))
53 {
54 $outputlist[ ucwords(strtolower($word)) ]++;
55 }
56 }
57
58 arsort($outputlist);
59
60 foreach ($outputlist AS $word => $count)
61 {
62 if (($_POST['ignoresmalls'] AND $count > 3) OR !$_POST['ignoresmalls'])
63 {
64 echo "<tr>\r\t<td>$word</td>\r\t<td>$count</td>\r</tr>\r";
65 }
66 }
67
68 echo "</table>\r<br />";
69 }
70
71 // ### START HTML ####################################################
72 ?>
73
74 <form action="wordrunner.php" method="post" name="wordrunner">
75 <input type="hidden" name="do" value="init">
76 <textarea name="wordtext" rows="60" cols="20" style="width:75%; height:50%"><?= $wordrunner_text ?></textarea>
77 <div><input type="submit" name="submit" value=" Run Words " /> <input type="checkbox" name="ignoresmalls" value="1" checked="checked" />Ignore Words With Small Counts</div>
78 </form>
79
80 <div align="center">WordRunner &copy;2004 Robert Sesek</div>
81
82 </body>
83 </html>