Searching for string in text file help?
| From: | Tim Loepp | Date: | Fri, 28 Jun 2002 23:43:01 +0000 |
| Subject: | Searching for string in text file help? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-104691@lists.php.net to get a copy of this message | ||
Hello, I'm hoping someone can help me as I' new to this and can't figure it
out myself.
PHP4.20 Win32
I'm trying to seach for a string that would occur about 10 lines into a text
file. I don't want to search the entire file, and I just want to know if the
string exsists or not, but I don't really know what I'm doing. This is what
I was trying, it occurs inside a loop that is listing the files in a
directory.
$fp = fopen("$target_filename", "r");
$contents = fgets("$fp","4096");
if(strstr("$contents", "$search_str"))
{
echo "<pre>";
readfile("$target_filename");
echo "</pre>";
}
Thanks
Tim Loepp