preg_match question

Discussion in 'PHP' started by triper, Nov 11, 2009.

  1. #1
    I have this HTML code exp.
    Lorem ipsum dorem, <a href="http://example.com/link1">link</a> koloris dominu trapem <a href="http://example.com/link1">link</a> op absb <strong>tip</strong>.
    
    Code (markup):
    With preg_match i need just text, can someone show me how, i know to remove all and inside <>, but firs time I need also inside code.
    The result must be:
    Lorem ipsum dorem, link koloris dominu trapem link op absb tip.
    
    Code (markup):

     
    triper, Nov 11, 2009 IP
  2. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    So you basically want to strip the tags? Try this:

    <?php
    /**
     * Strip HTML Tags
     * Script by Dennis M.
     *
     */
    
    $text = 'Lorem ipsum dorem, <a href="http://example.com/link1">link</a> koloris dominu trapem <a href="http://example.com/link1">link</a> op absb <strong>tip</strong>.';
    
    $text = preg_replace("/<.+?>/","",$text);
    
    print $text;
    ?>
    PHP:
    Use preg_replace instead of preg_match.

    Regards,
    Dennis M.
     
    Dennis M., Nov 11, 2009 IP
  3. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use strip_tags() function:
    echo strip_tags('Lorem ipsum dorem, <a href="http://example.com/link1">link</a> koloris dominu trapem <a href="http://example.com/link1">link</a> op absb <strong>tip</strong>.');
    PHP:
     
    xenon2010, Nov 11, 2009 IP
  4. triper

    triper Member

    Messages:
    66
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #4
    Thanks a lot guys!
     
    triper, Nov 12, 2009 IP
  5. xenon2010

    xenon2010 Peon

    Messages:
    237
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    no problem..
     
    xenon2010, Nov 12, 2009 IP