By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,987 Members | 997 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,987 IT Pros & Developers. It's quick & easy.

preg_replace(not all tags)

P: n/a
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?
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a

* html {redirect-to: url(;}
Jul 17 '05 #2

P: n/a
porneL wrote:


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.

Jul 17 '05 #3

P: n/a
"pornel" wrote:
* 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:
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.