Richard Lynch wrote: > On Mon, March 12, 2007 8:05 pm, Myron Turner wrote: >> Richard Lynch wrote: >>> For something that simple in PHP4, I didn't even bother with the >>> 50-line expat lib solution... >>> >>> A couple preg matches, or even just strtok and call it done... >>> >>> //assume file_get_contents is too "new"... >>> //probably wrong, but be safe >>> $xml = implode('', >>> file('www.librarytools.com/events/sampledata.txt')); >>> >>> preg_match_all('|<result i="[0-9+]">.*<f >>> n="eventname">([^<]*)</f>.*(f >>> n="eventnextoccurrencedate">([^<]*)</f>)?|msiU', $xml, $eventdata); >>> >>> var_dump($eventdata); >>> >>> I probably got the regex wrong -- I usually do... >>> >> Of course, there are all kinds of hacks which can be used for simple >> situations--even sometimes complex situations. I recently wrote a >> Perl >> script for a complex screen-scraping task which by-passed all of >> Perl's >> standard parsers and used Perl's regular expression facilities. But >> then I know how to use Perl's parsers if I have to, as well as when >> not >> to use them if I prefer. So now Rob Gould, who asked the original >> question, knows a few things about the expat parser which he didn't >> understand before and will be able to use it in the future. That seems >> to me worthwhile, and more useful in the long run than scratching out >> a >> few regular expression hacks that have limited local applicability. > > In my experience, the pain of the expat library was worse more often > than it was useful, for the XML tasks I had to accomplish. > > Certainly if you need a generic XML handling sort of thing in PHP4, > and upgrading is not an option, go with expat. > > If you just need to parse some silly little XML file, a PCRE hack is > about 5 lines of code, and 5 minutes, instead of 5 days of typing. > > YMMV > > NOTE: > If you have any wiggle room at all, UPGRADE to PHP 5 for XML processing. > It's like night and day. yeah but don't forget your sunglasses, and never stare directly into the sun > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php