Page 1 of 1
Old browser strip function
Posted: Wed Oct 19, 2005 4:51 pm
by Shendemiar
Im trying to alter a wabpage to pure simple text+html for old browsers.
// This array is for stripping opening and closing tags AND what's in between
Code: Select all
$tags_and_content_to_strip = Array("title");
foreach ($tags_and_content_to_strip as $tag) {
$contents = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$contents);
}
I want to alter it to remove tags like span and div etc, that are of form <DIV something...>
So, i take the ">" of the expression, and add one " ", tried "\ " too, but no luck.
Posted: Wed Oct 19, 2005 5:26 pm
by feyd
when correctly implemented, an unknown tag is simply ignored.. last I checked..
Posted: Wed Oct 19, 2005 6:01 pm
by Shendemiar
Thanks, i allready got it:
Code: Select all
// poista <DIV...> JA </DIV>
$a = preg_replace("/<(D|d)(I|i)(V|v).(.|\s)*?>/","",$a);
$a = preg_replace("/<\/(D|d)(I|i)(V|v)>/","",$a);
// poista <SPAN...> xxx </SPAN>
$a = preg_replace("/<(S|s)(P|p)(A|a)(.|\s)*?<\/(S|s)(P|p)(A|a)(N|n)>/","",$a);
Posted: Wed Oct 19, 2005 6:07 pm
by feyd
Your span code will destroy the data it contains and will not find spans across multiple lines.
Your div code will have same for the latter issue if the tag itself spans across lines.
Posted: Wed Oct 19, 2005 6:55 pm
by Shendemiar
feyd wrote:Your span code will destroy the data it contains and will not find spans across multiple lines.
Your div code will have same for the latter issue if the tag itself spans across lines.
Span needs to clear all thats between the span. I'm rather proud of myself! How do i add the multiline support to it?
(Code i use this for, never have tag split in two lines, the stuff between yes, but no tag)
Posted: Wed Oct 19, 2005 8:39 pm
by feyd
use the s pattern modifier and add entire tag matching so that it'll handle across lines for the tags themselves.
Posted: Thu Oct 20, 2005 7:01 pm
by Skara
Though I don't believe the regex does what you want...
/<(S|s)(P|p)(A|a)(.|\s)*?<\/(S|s)(P|p)(A|a)(N|n)>/
should simply have an i modifier.
/<(s)(p)(a)(.|\s)*?<\/(s)(p)(a)(n)>/i
