Author Topic: XML Parsing  (Read 403 times)

0 Members and 1 Guest are viewing this topic.

Offline mentalistTopic starter

  • Enthusiast
  • Posts: 156
    • View Profile
    • www.rawstar7.co.uk
XML Parsing
« on: February 08, 2010, 07:57:52 PM »
I'm playing with twitter. I'm receiving an xml document and using preg_match_all on it. What i'm wanting to do is split it on the <user> tags. This is the code i'm trying...

Code: [Select]
preg_match_all('#<user>([.\s\n]*)</user>#',$s,$matches);

I've tried variations, all to no avail.
I'm actually unsure about the hash / pound 's at either end, but the example I got it from uses them...

Not sure if it's the angle brackets and such that's playing up...


Thanks for any help!

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,241
    • View Profile
Re: XML Parsing
« Reply #1 on: February 09, 2010, 01:55:39 AM »
There is the simplexml() extension which is useful for parsing xml.

Offline cags

  • Guru
  • Fanatic
  • *
  • Posts: 3,250
  • Gender: Male
    • View Profile
    • TiB Studios
Re: XML Parsing
« Reply #2 on: February 09, 2010, 05:24:29 AM »
The hash signs are correct and are one of many characters that you can use for delimiters. The problem is since you use the dot assertion inside a character class it has no special meaning, it will literally match only a dot. So you pattern looks for user tags that contains 0 or more fullstops or white-space characters. I assume your user tags have more than that between them.

But as thorpe said, you should really use a proper xml parser.
CodeCanyon - Cheap, High Quality, Ready Made Scripts.