Results 1 to 5 of 5

Thread: [RESOLVED] Help with preg_match function

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Resolved [RESOLVED] Help with preg_match function

    Hi all i am trying to use preg_match to get number of pages from a html that has this format :



    HTML Code:
    <div class="pagingOf">of </div><a class="pagingLink" href="javascript:__doPostBack('ctl00$cpMain$UserViewPictureControl$PagerTop','4')">4</a>
    in this case i want to grab the number 4 but it never works. Could any one tell me what



    PHP Code:
    global $curl;

    // Retrieve number of pages page.
        
    echo 'Checking friends list... ';
        
    curl_setopt($curlCURLOPT_URL'./test.html');
        
    curl_setopt($curlCURLOPT_POST0);
        
    $result curl_exec($curl);
        
    $headers curl_getinfo($curl);
        
        
    // Find out how many pages there are. 
        
    if (preg_match('~of <a href="(.+?)" class="pagingLink">([0-9]+)</a>~'$result$matches))
        {
            
    $pages $matches[2];
                echo 
    ' Number of pages: $pages ';
            unset(
    $matches);
            
        } 

  2. #2
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Help with preg_match function

    http://www.vbforums.com/showthread.php?t=527371
    http://www.vbforums.com/showthread.php?t=527310
    http://www.vbforums.com/showthread.php?t=527357

    You have to be joking that you've posted almost the exact same thing 3 times and still haven't sorted it? I gave you code that worked perfectly fine.
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help with preg_match function

    RudiVisser thanks for your reply. But if you look closely you see the html is different then previous one!! Before posing this i tried your solutions it didn't work for my current html:

    New html:
    HTML Code:
    of </div><a class="pagingLink" href="javascript:__doPostBack('ctl00$cpMain$UserViewPictureControl$PagerTop','4')">4</a>

    old html:

    HTML Code:
    of <a href="javascript: GotoPage(4);" class="pagingLink">4</a>

  4. #4
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Ubuntu Haters Club
    Posts
    405

    Re: Help with preg_match function

    Well then you look closely and I'm sure you'll figure it out:
    HTML Code:
    of </div><a class="pagingLink" href="javascript:__doPostBack('ctl00$cpMain$UserViewPictureControl$PagerTop','4')">4</a>
    PHP Code:
    'of <a href="(.+?)" class="pagingLink">([0-9]+)</a>' 
    What comes first in the opening tag?
    » Twitter: @rudi_visser : Website: www.rudiv.se «

    If Apple fixes security flaws, they are heralded as proactive. If Microsoft fixes a security flaw, they finally got around to fixing their buggy OS.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Help with preg_match function

    Thanks i fixed it :-)

    PHP Code:
    if (preg_match('%of </div><a class="pagingLink" href="(.+?)">([0-9]+)</a>%'$result$matches)) 

        
    $pages $matches[2]; 
        echo 
    'There are '.$pages.' pages.'


Posting Permissions

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



Click Here to Expand Forum to Full Width