I need to use a web crawler script to locate a url, and then use a word count to count the frequency of each word and display it with the script. This is what I have so far.
<form action="<? echo $PHP_SELF;?>" method=post>
URL: <input name=url size=30 value="<? echo $_POST['url']; ?>">
<input type=submit value=submit>
<input type=reset value=reset>
<input type=hidden name=submitted value=true>
</form>
</center>
<hr>
<?php
if ($_POST['submitted']){
$filename=$_POST['url'];
$file = fopen($filename, "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file);
}
fclose($file);
}
if ($_POST['submitted']){
$wordarray=explode(" ", $_POST['text']);
foreach ($wordarray as $value){
$freq{$value}++;
}
arsort($freq);
echo "<table border=1><tr><th>word</th><th>freq.</th></tr>";
foreach ($freq as $key=>$value){
if (strlen($key)>0){
echo "<tr><td>".$key."</td><td>".$value."</td></tr>";
}
}
echo "</table>";
}
?>
I know I need the first IF statement, but was going to get rid of everything after the first line and insert the word count function. Does this make sense to anyone?