sebasjuh Posted June 14, 2009 Share Posted June 14, 2009 Hello, I found this php forum with google in search for an answer to my question. I can't find the answer so I thought maybe I can try it on this forum.... This is my question: I'll have a curl function to get the data from a page, now i'm want the data between the <span class="Title"></span> and the data between the tag <a class='Link'></a>. If I use preg_match_all for the span tag i'll get the results but how can I check on 2 html tags? The code I have is this: (the $result value is the data from the curl command). Is is possible to make a $pattern with 2 tag's to search for? Or how can I else solve it? Hope someone can help me with it..... $pattern = '/<span\s+(?:.*?\s+)?class=([\"\'])Title\1\s*>\s*(?:.*?\s+)*?(.*?)\s*<\/span>/'; preg_match_all($pattern, $result, $matches, PREG_SET_ORDER); foreach ($matches as $val) { echo "Title: $val[0] <br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/162125-php-preg_match_all-problem/ Share on other sites More sharing options...
rea|and Posted June 15, 2009 Share Posted June 15, 2009 Try this one: $pattern = '/<(a(?=[^>]+class=(\'|")Link(?:\\2))|span(?=[^>]+class=(\'|")Title(?:\\3)))[^>]+>(.*?)<\/\\1>/si'; preg_match_all($pattern, $result, $matches, PREG_SET_ORDER); foreach ($matches as $val) { echo "Tag: {$val[1]} - {$val[4]}<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/162125-php-preg_match_all-problem/#findComment-856307 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.