Readability\Readability::clean PHP Method

clean() public method

(Unless it's a youtube/vimeo video. People love movies.). Updated 2012-09-18 to preserve youtube/vimeo iframes
public clean ( DOMElement $e, string $tag )
$e DOMElement
$tag string
    public function clean($e, $tag)
    {
        $currentItem = null;
        $targetList = $e->getElementsByTagName($tag);
        $isEmbed = $tag === 'audio' || $tag === 'video' || $tag === 'iframe' || $tag === 'object' || $tag === 'embed';
        for ($y = $targetList->length - 1; $y >= 0; --$y) {
            // Allow youtube and vimeo videos through as people usually want to see those.
            $currentItem = $targetList->item($y);
            if ($isEmbed) {
                $attributeValues = $currentItem->getAttribute('src') . ' ' . $currentItem->getAttribute('href');
                // First, check the elements attributes to see if any of them contain known media hosts
                if (preg_match($this->regexps['media'], $attributeValues)) {
                    continue;
                }
                // Then check the elements inside this element for the same.
                if (preg_match($this->regexps['media'], $targetList->item($y)->innerHTML)) {
                    continue;
                }
            }
            $currentItem->parentNode->removeChild($currentItem);
        }
    }