|
Posted by Tyrone Slothrop on 09/17/05 17:18
On Sat, 17 Sep 2005 14:52:11 +0300, Dimitris Mexis <dmexis@sparks.gr>
wrote:
>I have created a small script that searches a word with eregii through a
>page. Assume that it found the word, and reports me the string,
>1) Can I take the line of this word is shown...?
>2) Can I create a link to this part of this page?
You may want to use the file() function which treats each line of a
file as an array.
$lines = file('/path/to/file');
Then find which line numbers contain the word:
foreach ($lines as $line_num => $line) {
if (/*Your regex here run on $line*/) {
$match[] = $line_num;
}
}
//Then display the lines
foreach ($match as $which) {
echo "a href=\"#$which\">".$lines[$match]."\<a>\";
}
To add a link, you will have to rewrite the line in the source file.
(Leaving out a lot of code here)
#first read file then do replace
str_replace ($line, "<a name\"$line_num\">$line</a>", $file);
// and then display the file
echo $file;
Navigation:
[Reply to this message]
|