I'll give you some suggestions and a little code examples, but you shuld at least attempt it. Then ask for help when you hit a wall. When trying to determine how to do anything in PHP I always go to PHP.net, it's the best source in my opinion.
If you look up the information for a string function, there will usually be links to related functions on the page. This is a good way to determine which is the best function to use in a particular case.
I will try to provide a means to get the keywords and their associated 5 charactrer values. I won't cover opening an htm file to read or writing out to a text file.
[NOTE: I have added periods at the beginning of some lines of code to aid in readability]
Assuming the contents of the htm file have been read into the variable $source:
First I would set up an array with the keywords to search for:
$keywords = array ('word1','word2','word3');
Then create control variables:
$keyword = "";
$foundSet = array();
Then loop through the keywords and do the heavy lifing:
//Loop through each keyword
foreach ($keywords as $value) {
.$position = 0;
.//Loop through all occurances of keyword
.while (strpos($source,$value,$position)) {
..//Set variable to start of 5 character value
..$foundPos = strpos($source,$value,$position)+strlen($keyword);
..//Create new record if 1st time found
..if ($keyword!=$value) {
...$keyword = $value;
...$foundSet[$keyword] = array();
..}
..$foundSet[$keyword][count($foundSet[$keyword])] = substr($source,$foundPos,5);
..//reset position
..$position = $foundPos+5;
.}
}
When all is said and done you should have an array in the format:
Array
(
..[keyword1] => Array (
....[0] => value1
....[1] => value2
....[2] => value3
....)
..[keyword2] => Array (
....[0] => value1
....[1] => value2
....[2] => value3
....)
..[keyword2] => Array (
....[0] => value1
....[1] => value2
....[2] => value3
....)
)
Michael J