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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post

    Having problem with preg_match

    Can anyone tell me why I am not just getting the URL from the below code returned in $matches[1]..... The returned URL starts correctly, but it also includes a ton of data after the closing quotes after the URL portion is finished.

    Code:
    if (preg_match('~</script><br /><br /><a href="(.+)" class="link" target="_blank">~i',$html,$match)) {
    // blah
    }
    Thanks!

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Probably because your regexp is greedy. Try (.+?) instead of (.+), or put the modifier U at the end of your regexp.

  • #3
    Regular Coder
    Join Date
    Apr 2004
    Posts
    684
    Thanks
    24
    Thanked 1 Time in 1 Post
    Thanks..... I actually changed it to the below..

    Code:
    if (preg_match('~</script><br /><br /><a href="([^"]+)" class="link" target="_blank">~i',$html,$match)) {
    // blah
    }
    Dunno why I didn't notice that earlier.


  •  

    Posting Permissions

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