Page 1 of 1

[noob] Need help

Posted: Sat Jan 24, 2009 2:10 pm
by czech_d3v3l0p3r
Hello everybody.

I'm pretty noob in regexes and I need a help assembling an expression.

So basicly I have something like this HMTL code:

Code: Select all

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#9633; <a target=blank href="/members/[color=#4080FF]1234[/color]">[color=#FF8040]User01[/color]</a> <a href="javascript&#058;;" onclick="ShowDiv('gUser01');"><img src="http://site.com/arrow.gif"></a><span id="gAmen" style="display:none"><ul><img src="http://sizr.com/ico/dline.gif"> <b>User01's group memberships:</b><br><br>
- [color=#408000]Maps[/color]<br>
- [color=#408000]Sprites[/color]<br>
- [color=#408000]Textures[/color]<br>
- [color=#408000]Scripts[/color]<br>
- [color=#408000]Sounds[/color]<br>
- [color=#408000]Posts[/color]<br>
- [color=#408000]IP search[/color]</ul></span><br>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#9633; <a target=blank href="/members/[color=#4080FF]45678[/color]">[color=#FF8040]User02[/color]</a> <a href="javascript&#058;;"  onclick="ShowDiv('gUser02');"><img src="http://sitep.com/arrow.gif"></a><span id="g[$carface]" style="display:none"><ul><img src="http://site.com/ico/dline.gif"> <b>User02's group memberships:</b><br><br>
- [color=#408000]Assessments[/color]<br>
- [color=#408000]Appeals[/color]<br>
- [color=#408000]Clubs[/color]<br>
- [color=#408000]Forum[/color]<br>
- [color=#408000]Gaghammer[/color]<br>
- [color=#408000]GUIs[/color]<br>
- [color=#408000]IP search[/color]<br>
- [color=#408000]News[/color]<br>
- [color=#408000]Posts[/color]<br>
- [color=#408000]Sprites[/color]<br>
- [color=#408000]Users[/color]</ul></span><br>
 
and I'd like to get the highlighted data: User ID, User Name, User's Group Memberships. BTW I'm using PHP's preg_match_all( $pattern, $subject, &$matches ); function.

Any help would be greatly appreciated.

PS: Sorry for my bad English and not much details provided I'm a bit tired.

Re: [noob] Need help

Posted: Sat Jan 24, 2009 2:14 pm
by prometheuzz
czech_d3v3l0p3r wrote:...
not much details provided I'm a bit tired.
Well, perhaps you should get a good night's sleep and then post back with enough details and perhaps post what you have tried so far.
I mean, you wouldn't like it if people started answering your question without actually reading your question or providing wrong answers just because they were too tired to post a proper answer, right?

Re: [noob] Need help

Posted: Tue Jan 27, 2009 11:24 am
by czech_d3v3l0p3r
prometheuzz wrote:
czech_d3v3l0p3r wrote:...
not much details provided I'm a bit tired.
Well, perhaps you should get a good night's sleep and then post back with enough details and perhaps post what you have tried so far.
I mean, you wouldn't like it if people started answering your question without actually reading your question or providing wrong answers just because they were too tired to post a proper answer, right?
Thanks.

And here's what I tried so far:

Code: Select all

$subject = file_get_contents(URL);
$matches = array();
preg_match_all("@<a .*?href=\"/members/(\d+)\">(.*?)</a>.*?</b><br><br>\n*(- ([a-z]+).*?<br>)+@im", $subject, &$matches);
but it returned nothing.

Thanks in advance for any suggestions.

Re: [noob] Need help

Posted: Tue Jan 27, 2009 1:02 pm
by prometheuzz
Okay, it's not possible to do this in one go since the "membership" list does not have a fixed size per user. You could do it like this:

Code: Select all

<?php
$text =<<< BLOCK
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#9633; <a target=blank href="/members/1234">User01</a> 
<a href="javascript&#058;;" onclick="ShowDiv('gUser01');"><img src="http://site.com/arrow.gif">
</a><span id="gAmen" style="display:none"><ul><img src="http://sizr.com/ico/dline.gif"> 
<b>User01's group memberships:</b><br><br>
- Maps<br>
- Sprites<br>
- Textures<br>
- Scripts<br>
- Sounds<br>
- Posts<br>
- IP search</ul></span><br>
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#9633; <a target=blank href="/members/45678">User02</a> 
<a href="javascript&#058;;"  onclick="ShowDiv('gUser02');"><img src="http://sitep.com/arrow.gif">
</a><span id="g[\$carface]" style="display:none"><ul><img src="http://site.com/ico/dline.gif"> 
<b>User02's group memberships:</b><br><br>
- Assessments<br>
- Appeals<br>
- Clubs<br>
- Forum<br>
- Gaghammer<br>
- GUIs<br>
- IP search<br>
- News<br>
- Posts<br>
- Sprites<br>
- Users</ul></span><br>
BLOCK;
 
if(preg_match_all('@href="/members/(\d+)"[^>]*>([^<]*).*?<ul>(.*?)</ul>@is', $text, $matches, PREG_SET_ORDER)) {
  foreach($matches as $match) {
    echo "ID={$match[1]}, name={$match[2]}\n";
    if(preg_match_all('/(?<=-\s)[^<]*/', $match[3], $memberships)) {
      print_r($memberships);
    }
  }
}
?>

Re: [noob] Need help

Posted: Tue Jan 27, 2009 5:21 pm
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.

Re: [noob] Need help

Posted: Wed Jan 28, 2009 6:44 am
by czech_d3v3l0p3r
prometheuzz wrote:Okay, it's not possible to do this in one go since the "membership" list does not have a fixed size per user. You could do it like this:

...code...
You're an awesome guy! Thank you very much, that really helped me. ^_^

Re: [noob] Need help

Posted: Wed Jan 28, 2009 7:45 am
by prometheuzz
czech_d3v3l0p3r wrote:
prometheuzz wrote:Okay, it's not possible to do this in one go since the "membership" list does not have a fixed size per user. You could do it like this:

...code...
You're an awesome guy! Thank you very much, that really helped me. ^_^
; )
Thanks, and you're welcome.