PHP - Count number of words
Hi
I have recently started coding in PHP. It is really good and I liked it very much. I have done some small programs in PHP. From few day I am just wondering that is it possible to count how many times a word i repeated on an external site. That is want to code a program that will count a word repeated on an external site and it will display an output. is it possible? I am not so sure that my question is correct or this can be done or not. If it is possible to do, then can you guys post me some codes so that I can study them. Thanks in advance.
Re: PHP - Count number of words
Hi
I think you can try something like this
Code:
$cnt = 0;
while($conts = file_get_conts("URL")){
$cnt = substr_cnt($conts,"$your_string");
}
I have not tested it, but still, i think this will work. Have a try at it. If any more queries do post back.
Re: PHP - Count number of words
Hi
May be this program is what you are looking for. Just go through it
Code:
$cnt = 0;
$t=0;
$conts = file_get_conts("URL");
$leng=strlen($conts);
for ($i=0;$i<$leng;$i++);
if($conts[$i]==" " && $conts[$i+1]!=" ")
{$arrstr[$t]=$conts[$i+1];
$t++;
}
$len=cnt($arrstr);
$ct=0;
for ($i=0;$i<$len;$i++);
{
for ($j=0;$j<$leng;$j++)
{if($arrstr[$i]==$conts[$j])
$ct++;
}
$ntime[$q]=$ct;
$ct=0;
}
$j=0;
for ($i=0;$i<$len;$i++);
{
echo "Number of time the words" . $arrstr[$i]."repeats is".$ntime[$j];
$j++;
}
Do not forget to post the feedback.
Re: PHP - Count number of words
Hi
The above should work fine. But I am posting you a part of the code. Just read it carefully and you can create a program that you were talking about.
Code:
$url = 'http://www.google.com/';
$conts = strtolower(strip_tags(file_get_conts($url)));
$conts = preg_replace('%[^\w\s\r\n]%', ' ', $conts);
$wds = preg_split('%[\s\r\n]+%', $conts);
$wdcnt = array_count_values($wds);
asort($wdcnt);
echo '<pre>'.print_r($wdcnt, true).'</pre>';
If you have any more queries then feel free to post back again. Enjoy programming.