Get file contents
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
Find what you're looking for
$pos = strpos($contents, $searchStr);
Then get a substring surrounding that position
$extract = '... ' . substr ($contents, $pos-x, strlen($searchStr) + 2*x) . '...';
echo $extract;
hth