![]() |
|
|
|
|
|
|
2
2nd July 03:19
External User
Posts: 1
|
Do you mean that all the other tags return the proper content
except the last one? I didn't study the code too closely for reasons that follow. Glad you asked Here are a couple things I noticed:- every call to this function has the overhead of reading the file. - The parsing is error prone, ie. someone puts: <bttag=bassie > If its possible I would take a complete different approach at parsing the tags. There are two options that I see right away. Use XML as your data format and an xml parser to obtain the values in the tags. Or use preg_match_all. Here is how I would approach the preg_match_all: function parseTags($file) { /* readfile... here */ $tag_match = "!<bttag=(\w*)>\s*([^<]*)\s*</bttag>!is"; preg_match_all($tag_match, $filedata, $matches); for ($i=0; $i< count($matches[0]); $i++) { $tagname = $matches[1][$i]; $tags[$tagname] = $matches[2][$i]; } return $tags; } Then you can use it like so: <?php $bttags = parseTags('test.tag'); ?> <HTML> <BODY> <h1>Test readTag-functie</h1> <?php echo $bttags['bassie']; ?> </body> </html> HTH, Curt -- "My PHP key is worn out" PHP List stats since 1997: http://zirzow.dyndns.org/html/mlists/ |
|