kauja pret html kaitniekiem :)
Nesen sapiktojos par to, ka viens neuzmanīgs cibiņš, kurš pavisam nejauši ieraksta savā pukstā </div> (protams, bez atbilstoša atverošā <div>), var galīgi izjaukt visu manu (ārprātīgi glīto :D) layout.
(Un tabulu layout-iem droši vien kaut kas līdzīgs notiek, ja ieraksta noslēdzošo td vai tr vai table.)
Rezultātā uztapa
šis te:
######################################
function validated_tag (string tag) : string {
var string[] tagsallowed = [ "br", "br/", "br /", "/a", "/span",
"b", "s", "i", "code", "blockquote", "em", "strong", "p",
"/b", "/s", "/i", "/code", "/blockquote", "/em", "/strong", "/p" ];
var string[] tagsskipped = [ "a ", "img ", "span class=", "lj user=" ];
var string[] tagsreplaced = [ "form ", "/form" ];
var string[] replaceto = [ "blockquote", "/blockquote" ];
var string tagl = $tag->lower();
var int i = -1;
foreach var string t ($tagsreplaced) { $i = $i + 1; if ($tagl->substr(0, $t->length()) == $t) { return "<" + $replaceto[$i] + ">"; } }
foreach var string t ($tagsskipped) { if ($tagl->substr(0, $t->length()) == $t) { return "<" + $tag + ">"; } }
foreach var string t ($tagsallowed) { if ($tagl == $t) { return "<" + $t + ">"; } }
# citus (neapstrādātos) tag-us vienkārši dzēšam
return "";
}
function striphtml2 (string s) : string {
var string result = "";
var string curr_tag = "";
var bool outside = true;
foreach var string ch ($s) {
if ($outside) {
if ($ch == "<") { $outside = false; }
else { $result = $result + $ch; }
} else {
if ($ch == ">") { $outside = true; $result = $result + validated_tag($curr_tag); $curr_tag = ""; }
else { $curr_tag = $curr_tag + $ch; }
}
}
return $result;
}
######################################
.
Jā, ir samērā Quick 'n Dirty, bet savu uzdevumu it kā pilda.
Poll-iem tiek izdarīts nedaudz sāpīgi, bet man tas pat iepatikās. Tikt pie balsošanas var tik un tā, caur poll-a linku.