tags:

views:

25

answers:

2

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?

A: 

one way,

$data = file_get_contents("file");
print strpos("$data","myword");
ghostdog74
Reading the entire contents of the file into memory could exhaust it.
Ignacio Vazquez-Abrams
"$data" seems redundant to me. Is that to catch null values or something?
Matchu
Its not really redundant like you said. $data, like any other variables, can be used later on in the code if required.
ghostdog74
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