string - search entire document instead of by line php -
ok, i'm trying list text files in php , need them contain number of 1 variable $words_to_match ='spaghetti'
, echo link. can see, text files total of strings (or 1 string each).
here code:
if($_post["confirmed"]=='') { echo "you need come in search!"; } else { $path_to_check = 'confirmed/'; $words_to_match = $_post["confirmed"];//checks form lastly page foreach(glob($path_to_check.'*.txt') $filename) { foreach(file($filename) $fli=>$fl) // not sure set here. { if (stristr($fl,$words_to_match) !== false) //or here. { echo '<a href="'.$filename.'">'.$filename.'</a><br />'; } } } }
i'm not sure set in spot says foreach(file($filename) $fli=>$fl)
or if (stristr($fl,$words_to_match) !== false)
. i'm pretty sure sec 1 right. when search file containing several lines of spaghetti
, shows several of same file. if there 3 lines of spaghetti
, there 3 files -- etc. want 1 of file listed, if there whole pile of spaghetti
in file. theory reads file line line, , gives output of of lines have spaghetti
in them.
to recap, want create have 1 listed file instead of how many lines contain string listed file.
any ideas?
btw, i'm using standard godaddy hosting business relationship php 5.3.
why not just:
foreach(glob(...) $filename) { if( stripos(file_get_contents($filename),$words_to_check) !== false) { // word present. } }
php string file-listing
No comments:
Post a Comment