Remove Links from source

Discussion in 'PHP' started by bumbar, Jun 7, 2009.

  1. #1
    Hallo!

    I have the following problem.I need to delete links and text in them.

    for example

    <a href=""> some text </ a>
    PHP:
    must remove it from the source.

    No only "some text", but all <a .. > ... </a>

    str_replace or maybe some ReGex

    Any Idea?

    Thanx!
     
    bumbar, Jun 7, 2009 IP
  2. HorseGalleria

    HorseGalleria Peon

    Messages:
    91
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use something like this:

    $buffer=preg_replace("/<a.*>/i","",$buffer);
     
    HorseGalleria, Jun 7, 2009 IP
  3. Sudoku-Master

    Sudoku-Master Peon

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    try this:
    
    $pattern="/^(.*)<a.*>(.*)</a>(.*)$/iU";
    $string="text with links";
    while (preg_match($pattern,$string,$matches))
    {
    $string=$matches[1].$matches[3]; # $matches[2] contains the linktext
    }
    print $string; #now without links
    
    Code (markup):
    a loop that match one link and rebuild the Text without that link...
     
    Sudoku-Master, Jun 7, 2009 IP