preg_replace(not all tags) (Answer)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CnapoB
    New Member
    • Oct 2013
    • 6

    #1

    preg_replace(not all tags) (Answer)

    I found this post by Google with question:
    http://bytes.com/topic/php/answers/1...e-not-all-tags "I need to replace all possible html tags in user input but don't want to
    replace bold and italic start and end tags, so I made folowing line, but
    it replaces only "one-letter-tags" like paragraf or underline tag, it
    doesn't replace body, div, span tags...
    Can anyone help me with this?
    Code:
    $txt = preg_replace('/<\/?[^bi]>/i', ' ', $txt);
    "
    May be my answer helps to another users:

    Just type
    Code:
    $txt = preg_replace('/\<\/?[^bi][^>]*\>/sU', ' ', $txt);
    For tags with 2 and big letters (br,img,hr) try this:
    Code:
    $txt = preg_replace('/\<\/?(?!br|img|hr)\b[^>]*\>/sU', ' ', $txt);
    Last edited by zmbd; Nov 4 '13, 10:11 PM. Reason: [z{place quote tags}{cleaned up grammer error created when I placed the quote tag}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    T.H.M.C: I asked CnapoB to start another thread with reference to an old thread due to posting issues; thus, I respectfully ask that CnapoB's post be treated as a continuation of the old thread for commenting, peer review etc...
    -z

    Comment

    Working...