php read file error? why doesn't this work??

i’ve spent a few hours trying to figure this one out, i’ve never used fopen before not sure if it needs to be in loop or not i’ve tried a varity of ways

just trying to get an end result which loads a txt file counts how many times each word has been used and echos the results

<?php $text = fopen("words.txt", "r"); $textarray = explode(" ",$text); foreach($textarray as $numbers) { if(isset($str_count[$numbers])) $str_count[$numbers]++; else $str_count[$numbers]=1; } foreach($str_count as $words => $numbers) echo $words.": ".$numbers."
"; ?>

fopen - prepares a file for operations on it. returns a resource handle for further operations
file_get_contents - returns the file contents.

Remember to go to use the online manual http://php.net/manual/en/function.file-get-contents.php
as it will give you lots of information and examples :slight_smile:

Brilliant thanks for the point in the right direction

now fixed

Ta

Sponsor our Newsletter | Privacy Policy | Terms of Service