Example #1
0
function clean_tag($tag)
{
    $clean = "";
    $tag = trim($tag);
    if (substr($tag, 0, 1) == "/") {
        $end = true;
        $tag = substr($tag, 1);
    } else {
        $end = false;
    }
    $type = string_next($tag, " ");
    //print "type [$type]\n";
    if ($type == "br") {
        return "<br/>";
    }
    if ($type == "b" || $type == "i" || $type == "u" || $type == "s" || $type == "q" || $type == "strong" || $type == "em") {
        if ($type == "strong") {
            $type = "b";
        } else {
            if ($type == "em") {
                $type = "i";
            }
        }
        if ($end) {
            return "</{$type}>FORCEWHITESPACE";
        } else {
            return "FORCEWHITESPACE<{$type}>";
        }
    }
    //if ($type == "p"  || $type == "ol" || $type == "ul" || $type == "li" || $type == "pre") {
    //if ($type == "pre") {
    if ($type == "ol" || $type == "ul" || $type == "li" || $type == "pre" || $type == "blockquote") {
        if ($end) {
            return "</{$type}>";
        } else {
            return "<{$type}>";
        }
    }
    if ($type == "a") {
        if ($end) {
            if ($type == "a") {
                return "</a>FORCEWHITESPACE";
            } else {
                return "</{$type}>";
            }
        }
        $tag = str_replace(" ", "", $tag);
        $tag = str_replace("\"", "\" ", $tag);
        $tag = str_replace("=\" ", "=\"", $tag);
        $tag = trim($tag);
        $map_old = map_from_tag_string($tag);
        $map_new = array();
        if ($type == "a") {
            $map_new["href"] = @$map_old["href"];
        }
        if (count($map_new) == 0) {
            return "<{$type}>";
        } else {
            if ($type == "a") {
                return "FORCEWHITESPACE<{$type} " . map_to_tag_string($map_new) . ">";
            } else {
                return "<{$type} " . map_to_tag_string($map_new) . ">";
            }
        }
    }
    return "";
}
Example #2
0
function map_from_attribute_string($s)
{
    $map = array();
    $a = explode(";", $s);
    for ($i = 0; $i < count($a); $i++) {
        $value = $a[$i];
        $name = trim(string_next($value, ":"));
        $value = trim($value);
        if ($name != "") {
            $map[$name] = $value;
        }
    }
    return $map;
}