After fopen, can I search for a keyword in PHP?
If I use fopen
on a file, is there any way to scan through the file to find the number of bytes a certain keyword begins at? If not, how can I do t开发者_Python百科his?
one way,
$data = file_get_contents("file");
print strpos("$data","myword");
The way you phrase this question makes it sound like you're looking for something other than basic string manipulation. If that's what you're saying - nope, string functions are your only option.
Just get the content as you normally would.
$content = fread($file_handle, filesize($filename));
$index = strpos($content, 'keyword');
精彩评论