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 5 of 5
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Regex Help... Again :(

    I've used that title before according to my browser.. i have to say i'm not surprised, it's my total nemesis.

    Anyway, onto my problem. I have to find out the total number of pages on a website, via regex.

    So far I've come up with the following code

    PHP Code:

    if(preg_match("bytransfer\.php\?sltByCap=V&TransferType=GB&sltTransferred=0&sltCapPercent=&Find=Yes&hdnPage=([:digit:])'"$html$matches)){
        
        
    sort($match);
        
    $total_pages $match[count($match)];
        echo 
    $total_pages " pages";
        
    } else {
        
        echo 
    " - pregmatch didn't work";
        

    Predictably it gives me a

    Warning: preg_match(): Delimiter must not be alphanumeric or backslash in
    error message. Could someone tell me where I'm going wrong please, I'd be most grateful.

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You have to have a starting and ending character, such as # or ~

    PHP Code:
    "#bytransfer\.php\?sltByCap=V&TransferType=GB&sltTransferred=0&sltCapPercent=&Find=Yes&hdnPage=([:digit:])'#" 

  • Users who have thanked Mwnciau for this post:

    Snetty (01-18-2008)

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Snetty View Post
    Predictably it gives me a

    error message. Could someone tell me where I'm going wrong please, I'd be most grateful.
    I don't if this work, but as first step to fix you miss a '/' at the begining of the regex and one at the end.

    PHP Code:
    if(preg_match("/bytransfer\.php\?sltByCap=V&TransferType=GB&sltTransferred=0&sltCapPercent=&Find=Yes&hdnPage=([:digit:])/'"$html$matches)){ 
    best regards

  • Users who have thanked oesxyl for this post:

    Snetty (01-18-2008)

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    And this might help you defeat your nemesis just yet....
    http://www.phpvideotutorials.com/regex
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • Users who have thanked StupidRalph for this post:

    Snetty (01-18-2008)

  • #5
    New Coder
    Join Date
    May 2005
    Posts
    94
    Thanks
    4
    Thanked 0 Times in 0 Posts
    thanks alot guys, I got it working without the tutorial but watched it anyway. I'm not going to be premature and say i've defeated that nemesis, but he's certainly running scared


  •  

    Posting Permissions

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