Preg Match Url

Discussion in 'PHP' started by nura235, Aug 5, 2010.

  1. #1
    nura235, Aug 5, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    emm.. there both the same link, I mean the end result is the same ?

    Anyway could you explain a little more, like whats the purpose, do you need to get something from the link etc... either way this little code will test for a match or not.

    
    <?php
    
    $link = "";
    
    if (eregi("http://netload.in/datei(.*).htm",$link)) {
    
    echo "Its a match";
    
    } else {
    
    echo "No match found";
    }
    ?>
    
    PHP:
     
    MyVodaFone, Aug 5, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    <?php
    $url = 'http://netload.in/dateieaae4f6c0ca5cce45152b50f4c86d481/dnb-dl.part7.rar.htm';
    if (preg_match('~http://(www\.)?netload\.in/datei.+?\.htm~i', $url)) {
    echo 'Valid';
    } else {
    echo 'Invalid';
    }
    ?>
    PHP:
     
    danx10, Aug 5, 2010 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    Stay away from everything that begins with ereg*... it's very very insecure, and deprecated.

    Be careful with the regex above. It would allow users to insert HTML in the URL, so filter it properly before outputting it to your users (if that's the plan anyway).
     
    nico_swd, Aug 7, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    If the OP is not displaying (ie. echo or print) the URL, then its okay...however if the OP is then filter it via htmlspecialchars()
     
    danx10, Aug 7, 2010 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Either that, or fix the pattern. ;p
     
    nico_swd, Aug 9, 2010 IP