function for removing link

Discussion in 'PHP' started by myinnet, Sep 15, 2006.

  1. #1
    i need a code to remove the link from a String, here is the sample:


    This is a test. <a href="http://www.domain.com">my site</a>
    here is the 2nd line
    .;....
    link againL
    <a href="http://www.domainsss.com">my 2nd site</a>
    Code (markup):
    I need a function to output it as

    Code:

    This is a test. my site
    here is the 2nd line
    .;....
    link againL
    my 2nd site
    Code (markup):
    thanks for your help.
     
    myinnet, Sep 15, 2006 IP
  2. VONRAT

    VONRAT Banned

    Messages:
    181
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    strip_tags() ..... ???? not sure what you want ... but you could try that function
     
    VONRAT, Sep 16, 2006 IP
  3. discoverclips

    discoverclips Peon

    Messages:
    491
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    $value = '<a href="http://www.domain.com/123.html">123</a>';
    
    echo preg_replace('/<a href="(.*?)">(.*?)<\\/a>/i', '$2', $value);
    
    PHP:
     
    discoverclips, Sep 16, 2006 IP
  4. intoex

    intoex Peon

    Messages:
    414
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    better use strip_tags
    $string = strip_tags($string, '<a>');
     
    intoex, Sep 17, 2006 IP
  5. tangtang

    tangtang Peon

    Messages:
    42
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Doesn't that leave the links?
     
    tangtang, Sep 17, 2006 IP
  6. Josh-H

    Josh-H Active Member

    Messages:
    406
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #6
    My thoughts exactly
     
    Josh-H, Sep 17, 2006 IP
  7. Josh-H

    Josh-H Active Member

    Messages:
    406
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    55
    #7
    Double post sorry
     
    Josh-H, Sep 17, 2006 IP
  8. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
  9. Icheb

    Icheb Peon

    Messages:
    1,092
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #9
    He wants LINKS removed, nowhere did he say he wants all HTML tags removed. discoverclips' example is perfectly fine.
     
    Icheb, Sep 17, 2006 IP
  10. myinnet

    myinnet Peon

    Messages:
    81
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    i am sorry for the delay to get back, This one is works fun for me, but strip_tags removes all the HTML tags.
     
    myinnet, Sep 18, 2006 IP