开发者

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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜