Jump to content

XML Parsing


mentalist

Recommended Posts

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

 

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.