You are here: Re: PHP Search & Links « All PHP « IT news, forums, messages
Re: PHP Search & Links

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация