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 this?
views:
25answers:
2
A:
one way,
$data = file_get_contents("file");
print strpos("$data","myword");
ghostdog74
2010-01-19 04:03:11
Reading the entire contents of the file into memory could exhaust it.
Ignacio Vazquez-Abrams
2010-01-19 04:16:50
"$data" seems redundant to me. Is that to catch null values or something?
Matchu
2010-01-19 04:17:19
Its not really redundant like you said. $data, like any other variables, can be used later on in the code if required.
ghostdog74
2010-01-19 04:32:23
A:
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');
Matchu
2010-01-19 04:06:42