protected function build($m)
    {
        $string = $m[1];

        if (substr($string, 0, 1) != '<') {
            // We matched a lone ">" character.
            return '&gt;';
        } elseif (strlen($string) == 1) {
            // We matched a lone "<" character.
            return '&lt;';
        }

        if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9\-]+)([^>]*)>?|(<!--.*?-->)$%', $string, $matches)) {
            // Seriously malformed.
            return '';
        }

        $slash = trim($matches[1]);
        $elem = &$matches[2];
        $attrlist = &$matches[3];
        $comment = &$matches[4];

        if ($comment) {
            $elem = '!--';
        }

        if (!in_array(strtolower($elem), $this->tags, true)) {
            return ''; // Disallowed HTML element.
        }

        if ($comment) {
            return $comment;
        }

        if ($slash != '') {
            return "</$elem>";
        }

        // Is there a closing XHTML slash at the end of the attributes?
        $attrlist = preg_replace('%(\s?)/\s*$%', '\1', $attrlist, -1, $count);
        $xhtml_slash = $count ? ' /' : '';

        // Clean up attributes.
        $attr2 = implode(' ', $this->explodeAttributes($attrlist));
        $attr2 = preg_replace('/[<>]/', '', $attr2);
        $attr2 = strlen($attr2) ? ' ' . $attr2 : '';

        return "<$elem$attr2$xhtml_slash>";
    }
protected function build($m)
    {
        $string = $m[1];

        if (substr($string, 0, 1) != '<') {
            // We matched a lone ">" character.
            return '&gt;';
        } elseif (strlen($string) == 1) {
            // We matched a lone "<" character.
            return '&lt;';
        }

        if (!preg_match('%^<\s*(/\s*)?([a-zA-Z0-9\-]+)([^>]*)>?|(<!--.*?-->)$%', $string, $matches)) {
            // Seriously malformed.
            return '';
        }

        $slash = trim($matches[1]);
        $elem = &$matches[2];
        $attrlist = &$matches[3];
        $comment = &$matches[4];

        if ($comment) {
            $elem = '!--';
        }

        if (!in_array(strtolower($elem), $this->tags, true)) {
            return ''; // Disallowed HTML element.
        }

        if ($comment) {
            return $comment;
        }

        if ($slash != '') {
            return "</$elem>";
        }

        // Is there a closing XHTML slash at the end of the attributes?
        $attrlist = preg_replace('%(\s?)/\s*$%', '\1', $attrlist, -1, $count);
        $xhtml_slash = $count ? ' /' : '';

        // Clean up attributes.
        $attr2 = implode(' ', $this->explodeAttributes($attrlist));
        $attr2 = preg_replace('/[<>]/', '', $attr2);
        $attr2 = strlen($attr2) ? ' ' . $attr2 : '';

        return "<$elem$attr2$xhtml_slash>";
    }
protected function build ( $ m ) { $ string = $ m [ 1 ] ; if ( substr ( $ string , 0 , 1 ) != '<' ) { // We matched a lone ">" character. return '&gt;' ; } elseif ( strlen ( $ string ) == 1 ) { // We matched a lone "<" character. return '&lt;' ; } if ( ! preg_match ( '%^<\s*(/\s*)?([a-zA-Z0-9\-]+)([^>]*)>?|(<!--.*?-->)$%' , $ string , $ matches ) ) { // Seriously malformed. return '' ; } $ slash = trim ( $ matches [ 1 ] ) ; $ elem = & $ matches [ 2 ] ; $ attrlist = & $ matches [ 3 ] ; $ comment = & $ matches [ 4 ] ; if ( $ comment ) { $ elem = '!--' ; } if ( ! in_array ( strtolower ( $ elem ) , $ this -> tags , true ) ) { return '' ; // Disallowed HTML element. } if ( $ comment ) { return $ comment ; } if ( $ slash != '' ) { return "</$elem>" ; } // Is there a closing XHTML slash at the end of the attributes? $ attrlist = preg_replace ( '%(\s?)/\s*$%' , '\1' , $ attrlist , - 1 , $ count ) ; $ xhtml_slash = $ count ? ' /' : '' ; // Clean up attributes. $ attr2 = implode ( ' ' , $ this -> explodeAttributes ( $ attrlist ) ) ; $ attr2 = preg_replace ( '/[<>]/' , '' , $ attr2 ) ; $ attr2 = strlen ( $ attr2 ) ? ' ' . $ attr2 : '' ; return "<$elem$attr2$xhtml_slash>" ; }
Build a filtered tag
@param array $m
@return string
Build a filtered tag