By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

preg_matching an XML node not working

P: 17
Does anyone know why the following isn't working, I'm losing my mind over this.


//if this is part of the xml file your loading
$str = '<xmlRoot>

<sample id="1">

<sample id="2">

//this dosn't match the first node only
preg_match('/<sample id\="1">[\S\s]*<\/sample>/',$str,$a);


Jan 8 '08 #1
Share this Question
Share on Google+
1 Reply

P: 17
Well, I fianlly got it.

this is the magic pattern:


$tag = 'sample id="1"';
$base = 'sample';

preg_match('/<' . preg_quote($tag) . '>([^`]*?)<\/' . $base . '>/i',$str,$a);


Jan 8 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.