Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newb help reading in config file

Status
Not open for further replies.

Xaqte

IS-IT--Management
Oct 4, 2002
971
US
I'm trying to read in a config file, formatted like:
Code:
<MESSAGE>
Tank number five exploded.
</MESSAGE>
<MESSAGE>
Tank #7 in need of repair
</MESSAGE>

I've been able to get the file contents by:
Code:
$comments = file_get_contents("data.txt");

And I've tried a number of "preg_match_all" statements, but I really suck at regular expressions.

My question is:
How can I find out the number of "MESSAGE" blocks in the file, and how would I go about looping through them and printing their contents?

I have searched this forum, and have come up short.

Thanks in advance for any thoughts/suggestions!

X
 
If your config file is well-formed XML, I suggest simpleXML (requires PHP5)
 
for newbie in PHP i found this site very very helpful
he recorded 6 lessons so far, he is very good at it teaching and explaing php.
 
Ok, I've found two scripts that work (sort of):

The only problem is that each of them only return the first node. I think this is because all of the nodes I'm parsing are the same (MESSAGE).

So, if anyone could help me.... I would really appreciate it!

Thanks again,

X
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top