Stripping a Link URL from a Comment (textarea)

Discussion in 'PHP' started by MikeLiao, Oct 8, 2009.

  1. #1
    How can I search and strip a link URL from a comment post and replace it with something like
    http://www.mydomain.com/redirect.php?c=http://www.poster_domain.com&a=123
    Poster's URL link can have a query string (?)

    or

    http://www.mydomain.com/redirect.php?c=http://www.poster_domain.com
     
    MikeLiao, Oct 8, 2009 IP
  2. MikeLiao

    MikeLiao Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    anyone?...
     
    MikeLiao, Oct 9, 2009 IP
  3. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #3
    how does the comment looks like?

    just "this is some text and my website is astrazone.com"

    or "this is some other text but my website is still <a href="astrazone.com">astrazone.com</a>"
     
    astrazone, Oct 9, 2009 IP
  4. lmao

    lmao Guest

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i think u need to use reg exp and replace all occurrence of anchor tags with your url proxy
     
    lmao, Oct 9, 2009 IP
  5. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #5
    $pattern = '/(<a[^>]*? href=")([^"]+)/si';
    function href_adjuster($matches) {
        return $matches[1].'http://www.mydomain.com/redirect.php?c='.urlencode($matches[2]);
    }
    
    $text = preg_replace_callback($pattern, 'href_adjuster', $text);
    PHP:
    This will urlencode the redirecting href, so you will need to do urldecode($_GET['c']) in redirect.php to get it back to the original
     
    JAY6390, Oct 9, 2009 IP
  6. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    if you still don't have it, i can make you such a php script but for $$$, if you are interested, just PM me how much you are willing to pay.
     
    w47w47, Oct 9, 2009 IP
  7. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Why would he pay when I've given the solution above???
     
    JAY6390, Oct 9, 2009 IP
  8. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    sry... i didn't red the whole thread only the title and just replayed. :S sry...
     
    w47w47, Oct 10, 2009 IP