It's possible, but complex. Use explode(); to organize the lines into an array. Use foreach() statement to use strpos(); to find lines that start with the text that begins with {string}.
Here's the code for it: {
PHP Code:
<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$text = fread($fh, filesize($myFile));
fclose($fh);
//the file was opened and read, now, the fun begins:
$text = "first sentence\nsecond sentence\nsentence sentence"; // text to find
$toFind = "sentence"; // what to search for.
$tnt = explode("\n", $text);
foreach($tnt as $txt) {
$str = strpos($text, $toFind);
if($str === FALSE) {
print "text not found";
} else {
print $txt; // print the text which has the matching "sentence" in front of it.
}
?>
and of course, your text file [here named, testFile.txt] would look like this:
Code:
first sentence
second sentence
sentence sentence
HTH
Bookmarks