After php reads a text file and opens it with fopen, it will read it in one row, and filter it out starting with # and @. If & lt; node & gt; or & lt; leaf & gt; (start to read when the tag starts) the three attributes in the read, and the next tag & lt; leaf & gt; or & lt;/leaf & gt; or & lt; /node & gt php reads text files
When fopen is enabled, one row is read, and the values starting with # and @ are filtered out. Or (Start to read when the tag starts) read the three attributes, and then the next tag Or Or Then, take out the first three elements as an array, that is, read the array of three elements in the middle of each tag for processing.
How to write this method?
# Vision1.1
@ Fileid = 0010.
Name = xx
Id = 0
Orth = zzz
Name = xx
Id = 801
Orth =/btf/sub.txt
Name = xx
Id = 101
Orth =/bbs/test.txt
------ Solution --------------------
Filter the # and @ of the first two rows for processing, from Start:
When $ FirstNode =" "; Make $ firstNode =" ";
Then one row is processed to determine if the current row is =$ firstNode,
So far...
This is To retrieve all the contents.
As for <>... regular expression processing ..
------ Solution --------------------
PHP code
$ Fn = 'data2.txt '; $ fp = fopen ($ fn, 'r'); $ s = ''; while ($ buf = fgets ($ fp )) {if (in_array ($ buf {0}, array ('#', '@') continue; if ($ buf {0} = '<') {if ($ s) {parse_str ($ s, $ t); $ r [] = $ t; $ s = '';} continue;} $ s. = ($ s? '&': ''). $ Buf;} fclose ($ fp); print_r ($ r );
------ Solution --------------------
You can solve the problem by nagging the boss. you should.