开发者

After fopen, can I search for a keyword in PHP?

开发者 https://www.devze.com 2022-12-16 16:27 出处:网络
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,

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

精彩评论

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

关注公众号