preg_replace(not all tags)

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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?

$txt = preg_replace('/<\/?[^bi]>/i', ' ', $txt);

and problem more: I would like to keep <br> tag and would like to change
<p> to <br> (and discard </p>)... and... that's it.

(just as idea, those |?\/... are very confusing to me. I'm still novice
in php)

no_html ($txt) {
  $input  = array ("'<p>tag'",

  $output = array ("'<br>'"
                   "' '");

  $txt = preg_replace ($input, $output, $txt);

Jan ko?

Re: preg_replace(not all tags)


* html {redirect-to: url( );}

Re: preg_replace(not all tags)

porneL wrote:
Quoted text here. Click to load it
Be careful with this though. Allowing <b> also means allowing this:
<b STYLE="font: 72pt Times New Roman">TEXT HERE</b>

(Example by Paul Hudson in his excellent work: Practical PHP Programming

You may want to customize or create a wrapper around strip_tags when
used with exceptions.


Re: Re: preg_replace(not all tags)

"pornel" wrote:
 > strip_tags($input,"<i><b>");
 > --
 > * html {redirect-to: url( );}

Besides that, when I want to deal with exceptions like this, I usually
change the exceptions (using str_replace) to something else that regex
won’t catch, run the regex, and change them back.  This may be
inefficient at times (depending) but surely it is a lot less taxing on
my brain cells.

Posted using the interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL:
Visit Topic URL to contact author (reg. req'd).  Report abuse:

Site Timeline