Ache Posted November 5, 2008 Share Posted November 5, 2008 I have a text file and want to count on how many lines in it a certain string excists.For that I have written the following code, but it is not working.<?php $prk = $_POST['prk']; $myFile = "testFile.txt"; $fh = fopen($myFile, 'r'); $aantal = 0; while (!feof($fh)) { $theData = fgets($fh); $pos = strpos($theData, $prk); if ($pos === true) { $aantal++; } } fclose($fh); echo $aantal; echo "<br>\n";?>If I change $aantal++; with $aantal = $aantal + 1; it also doesn't workWhat am I doing wrong? Link to comment Share on other sites More sharing options...
jeffman Posted November 5, 2008 Share Posted November 5, 2008 The problem might be here:if ($pos === true)Try this instead:if ($pos !== false) Link to comment Share on other sites More sharing options...
Ache Posted November 5, 2008 Author Share Posted November 5, 2008 I knew it had to be somthing simple Thanks, that solved it.Now I can continue with the rest I have in mind.Or perhaps I should say, up to the next problem Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.