$file = file_get_contents("myfile.txt"); $needle = "needle"; $countfile = substr_count($file, $needle); echo $countfile; Code (markup): This PHP code echoes 0 when I try to run it even though myfile.txt contains needle. Anyone know why? I guess I overlooked something obvious. myfile.txt: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer ullamcorper sapien ac tellus. Vivamus euismod. needle Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer ullamcorper sapien ac tellus. Vivamus euismod. Code (markup): EDIT: Disregard this topic, I used $file within something that already used the variable (a folder tree), thus is came out empty.
maybe the filename is incorrect, thats why there is no text getting in variable $file and showing 0 in substr_count.
Nope, I tried echoing $file and it printed the file without errors. :/ EDIT: Disregard this topic, I used $file within something that already used the variable (a folder tree), thus is came out empty.