Connecting Tech Pros Worldwide Forums | Help | Site Map

preg_replace(not all tags)

JaNE
Guest
 
Posts: n/a
#1: Jul 17 '05
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
--

porneL
Guest
 
Posts: n/a
#2: Jul 17 '05

re: preg_replace(not all tags)



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


--
* html {redirect-to: url(http://browsehappy.pl);}
Schraalhans Keukenmeester
Guest
 
Posts: n/a
#3: Jul 17 '05

re: preg_replace(not all tags)


porneL wrote:[color=blue]
>
> strip_tags($input,"<i><b>");
>
>[/color]
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
steve
Guest
 
Posts: n/a
#4: Jul 17 '05

re: preg_replace(not all tags)


"pornel" wrote:[color=blue]
> strip_tags($input,"<i><b>");
>
>
> --
> * html {redirect-to: url(http://browsehappy.pl);}[/color]

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
Closed Thread