Well i want to output how many times a word is repeated on an external site how would i do ths ?? can some1 post a sample code using file_get_contents
Would something like this work (not tested): $count = 0; while($contents = file_get_contents("URL")){ $count = substr_count($contents,"$your_string"); } PHP: Might have to use if rather than while and use that code in some sort of loop.
May this code solve your problem: $count = 0; $t=0; $contents = file_get_contents("URL"); $length=strlen($contents); for ($i=0;$i<$length;$i++); if($contents[$i]==" " && $contents[$i+1]!=" ") {$arrstr[$t]=$contents[$i+1]; $t++; } $len=count($arrstr); $ct=0; for ($i=0;$i<$len;$i++); { for ($j=0;$j<$length;$j++) {if($arrstr[$i]==$contents[$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++; } I have not tested it.
You can easily modify that and set a variable to hold that info and then check if end of file has been reached in the while loop.
$url = 'http://www.google.com/'; $contents = strtolower(strip_tags(file_get_contents($url))); $contents = preg_replace('%[^\w\s\r\n]%', ' ', $contents); $words = preg_split('%[\s\r\n]+%', $contents); $wordcounts = array_count_values($words); asort($wordcounts); echo '<pre>'.print_r($wordcounts, true).'</pre>'; PHP: Something like that? Just use echo $wordcounts['word_goes_here'];
so basically after fetching the url we just have to use the rest of the code u posted $contents = strtolower(strip_tags(file_get_contents($url))); $contents = preg_replace('%[^\w\s\r\n]%', ' ', $contents); $words = preg_split('%[\s\r\n]+%', $contents); $wordcounts = array_count_values($words); asort($wordcounts); echo '<pre>'.print_r($wordcounts, true).'</pre>'; i am not sure abt the curl thing so if u can confirm
$contents = strtolower(strip_tags(file_get_contents($url))); would be $contents = strtolower(strip_tags($url))); rite ??