Thanks for all the help. First of all, I can't do it by line because there are times when the data are on more than one line. For instance:
<MEMO>This is the memo field. It can have
several lines
It may also have HTML, which will be printed
exactly as it appears in the text data file
</MEMO>
I'm working with the first solution above (using preg_match), but I'm not sure if I'm using it correctly. First of all, here's how I'm opening the data file and loading it into a variable:
$data = implode('',file("text.txt"));
Is that wrong?
Then, I'm using preg_match, like this:
preg_match( '/<NAME>([^<]*)<\/NAME>/i', $data, $matches );
I haven't been able to get it to work yet, by the way.
And here is the entire parse function as it works in perl. (I use $vals{'NAME'} to print the variables in the Perl script.) I need this replicated as closely as possible in PHP:
sub parse_file{
$file_text = join '', @file_text;
%vals = ();
while ($file_text =~ /<(.+?)>(.+?)<\/.+?/sg) {
$vals{$1} = $2;
}
#return a value.
1;
}
Also, what are the additional variable in the preg_match function? For instance, how do I use the $matches variable? Is it an array that is used this way: $matches['0'], $matches['1'], or can I use the text within the < > like this: $matches['NAME']? Thanks again everyone for your help.