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.

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

no_html ($txt) {
$input = array ("'<p>tag'",
"'<br>,<b>,<i>,</b>,</i>tags"
"'<any_other>tag'");

$output = array ("'<br>'"
"'<br>,<b>,<i>,</b>,</i>tags'");
"' '");

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

--
Jan ko?
http://fotozine.org
--
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

strip_tags($input,"<i><b>");
--
* html {redirect-to: url(http://browsehappy.pl);}
Jul 17 '05 #2

P: n/a
porneL wrote:

strip_tags($input,"<i><b>");

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
at www.hudzila.org)

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

Schraalhans
Jul 17 '05 #3

P: n/a
"pornel" wrote:
strip_tags($input,"<i><b>");
--
* html {redirect-to: url(http://browsehappy.pl);}


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 http://www.dbforumz.com interface, at author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/PHP-preg_rep...ict188375.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbforumz.com/eform.php?p=639933
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.