1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to remove all content between tags?

Discussion in 'PHP' started by j0563, Jul 1, 2010.

  1. #1
    I am trying to remove all content between hyperlink tags. For example, if I start with this:

    I would like <a href="http://www.google.com">to remove</a> this link.
    Code (markup):
    I would like the result to be:

    I would like this link.
    Code (markup):
    I am trying to find all instances of <a> and </a> and remove everything between it using PHP...

    Any help on this??? Im thinking something using preg_replace?
     
    j0563, Jul 1, 2010 IP
  2. Boogy

    Boogy Active Member

    Messages:
    36
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    73
    #2
    You will need to use Javascript. I just sent you a pm.
     
    Boogy, Jul 1, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    Theres loads of ways to do it, it depends if your using other tags and so forth; rather quickly;

    <?php
    
    $str = 'I would like <a href="http://www.google.com">to remove</a> this link.';
    $filter = preg_replace("/<a(.*)<\/a>/iUs", "", $str);
    
    print $filter;
    ?>
    PHP:
    OUTPUT: I would like this link.
     
    lukeg32, Jul 1, 2010 IP
  4. Triggs

    Triggs Active Member

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #4
    Yes, regex would be the best.
    And for the record, don't send people PMs of the answer. People may need to find the answer later via search.
     
    Triggs, Jul 1, 2010 IP