Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts

    Simple regex help

    I'm trying to capture the 242334 from this

    PHP Code:
    <a href="member.php?u=242334">*Username*</a

    My code doesn't seem to work maybe its because the "*" in the username?

    PHP Code:
    if(preg_match_all('#<a.*href="member.php\?u=(\d+)".*>#Uis'$buf$match)) 
    Last edited by The_Return; 09-22-2009 at 01:01 AM.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    PHP Code:
    if(preg_match_all('#<a.*href="member.php\?u=(\d+)">#Uis'$buf$match)) 

  • #3
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts
    hmm still not working I'll post my whole code

    PHP Code:
    <?php

    if (isset($_POST['id'])) {

    $pages $_POST['pages'];


    $f fopen("http://forum.ebaumsworld.com/memberlist.php?&pp=30&order=asc&sort=username&aim=a&page=$pages","r");
    while( 
    $buf fgets($f,1024) ) 

    if(
    preg_match_all('#<a.*href="member.php\?u=(\d+)">#Uis'$buf$match))  

    for( 
    $i 0$match[1][$i]; $i++ ) 

    $numbers strtolower($match[$i]);
    if(!
    is_numeric($numbers)) continue;
    $file fopen("id.txt""a");
    print (
    "$numbers<br>");
    fputs($file"$numbers\r\n");
    fclose($file);




    if ( !
    $buf fgets($f,1024) )
    {
    echo 
    "User ids have been added to the list";
    }
    }
    ?>

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Change:

    Code:
    if(preg_match_all('#<a.*href="member.php\?u=(\d+)">#Uis', $buf, $match))  
    {
    to:

    Code:
    if(preg_match_all('#<a href="member.php\?u=(\d+)">#Uis', $buf, $match))  
    {
        print_r($match);
    and post the output.

  • #5
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Doesn't display anything , vbulletin changed their format in their newest version instead of having the whole link it shows just the members.php thats when I view the source in firefox but when in google chrome it shows something else take this forum as an example

    http://forum.ebaumsworld.com/memberl...e&aim=a&page=1

    in internet explore 8 when I view source I get this




    what I have noticed is that number I need is in the td class alt1Active where the id is this has not changed in all the browser version I viewed, all that needs to be removed is the"u"
    Last edited by The_Return; 09-22-2009 at 12:56 AM.

  • #6
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Untested. Try:

    Code:
    if (preg_match_all('#<a href="member.php\?.+u=(\d+)">#Uis', $buf, $match))

  • Users who have thanked MattF for this post:

    The_Return (09-22-2009)

  • #7
    Regular Coder
    Join Date
    Dec 2008
    Posts
    116
    Thanks
    11
    Thanked 4 Times in 4 Posts
    Thanks that worked perfectly

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You're welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •