Re: $35 to the first person who can do this XML-parsing PHP script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.
Myron Turner

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux