Strip HTML tags

@param  string $html The html content
@return string
516415
public static function stripTags($html, $charset = 'UTF-8')
    {
        $patterns = [
            '~<(style|script|head).*</\\1>~Uis' => '',
            '~<t[dh][ >]~i' => ' $0',
            '~<a\s[^>]*href=(?|"([^"]+)"|\'([^\']+)\')[^>]*>(.*?)</a>~is' => '$2 &lt;$1&gt;',
            '~[\r\n ]+~' => ' ',
            '~<(/?p|/?h\d|li|br|/tr)[ >/]~i' => "\n$0",
        ];

        $text = preg_replace(array_keys($patterns), array_values($patterns), $html);
        $text = html_entity_decode(strip_tags($text), ENT_QUOTES, $charset);
        $text = preg_replace('~[ \t]+~', ' ', $text);
        return trim($text);
    }
204755
private function extractTitle(string $html): string
    {
        $result = '';

        if (preg_match('/<title[^>]*>\s*(.*?)\s*<\/title\s*>/iu', $html, $matches)) {
            $result = html_entity_decode(strip_tags($matches[1]), ENT_QUOTES);
        }

        return $result;
    }
1318471
private static function convertHtmlToDom($html)
    {
        $dom = new DOMDocument;

        \libxml_use_internal_errors(true);
        $dom->loadHTML($html);

        \libxml_clear_errors();

        return $dom;
    }
447225
protected function tidy( $html ) {

		// Make XHTML 1.1 strict using htmlLawed

		$html = \Pressbooks\Interactive\Content::init()->replaceInteractiveTags( $html );

		$config = [
			'valid_xhtml' => 1,
			'no_deprecated_attr' => 2,
			'unique_ids' => 'fixme-',
			'deny_attribute' => 'itemscope,itemtype,itemref,itemprop,data*,aria*',
			'hook' => '\Pressbooks\Sanitize\html5_to_xhtml11',
			'tidy' => -1,
			'comment' => 1,
		];

		$spec = '';
		$spec .= 'img=-longdesc,-srcset;';
		$spec .= 'table=-border;';

		// Reset on each htmLawed invocation
		unset( $GLOBALS['hl_Ids'] );
		if ( ! empty( $this->fixme ) ) {
			$GLOBALS['hl_Ids'] = $this->fixme;
		}

		return \Pressbooks\HtmLawed::filter( $html, $config, $spec );
	}
700342
private function cleanupXss($html)
    {
        if (false === $this->config['xss_filter']) {
            return $html;
        }

        $this->logger->info('Filtering HTML to remove XSS');

        return htmLawed(
            $html,
            [
                'safe' => 1,
                // *+iframe: do not remove iframe elements
                'elements' => '*+iframe-meta',
                'deny_attribute' => 'style',
                'comment' => 1,
                'cdata' => 1,
            ]
        );
    }
1273117
public static function createLinks($html)
    {
        return preg_replace_callback(
            '!((?:https?\://|\b\www\.).*?)([.,;:]( |$|<)|[ <]|$)!',
            function ($m) {
                $url = $m[1];
                $html = $m[1];
                if (!preg_match('/^https?:/', $url)) {
                    $url = 'http://' . $url;
                }
                return sprintf('<a href="%s">%s</a>%s', $url, $html, $m[2]);
            },
            $html
        );
    }
1066206
static function removeHtmlTag($text)
    {

        $text = htmlspecialchars_decode($text);
        $text = html_entity_decode($text);
        $text = strip_tags($text);
        return $text;

    }
194490
public function removeTags($string)
    {
        // Remove HTML Tags:
        
        $string = preg_replace('/<[^>]*>/', ' ', $string);
        
        // Remove Control Characters:
        
        $string = str_replace("\r", '',  $string);  // replace with empty space
        $string = str_replace("\n", ' ', $string); // replace with single space
        $string = str_replace("\t", ' ', $string); // replace with single space
        
        // Remove Multiple Spaces:
        
        $string = trim(preg_replace('/ {2,}/', ' ', $string));
        
        // Answer String:
        
        return $string;
    }
286854
public function html($html = null)
    {
        if ($html === null) {
            return $this->_html;
        }
        $this->_html = $html;

        return $this;
    }
1246580
public function loadHTML($html)
    {
        $dom = new \DOMDocument();
        $dom->formatOutput = true;

        // strip illegal XML UTF-8 chars
        // remove all control characters except CR, LF and tab
        $html = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/u', '', $html); // 00-09, 11-31, 127

        $dom->loadHTML($html);
        $this->loadDomDocument($dom);
    }
261118
public static function strip($string)
    {
        $cleaned = strip_tags($string);
        $cleaned = Str::trim($cleaned);

        return $cleaned;
    }
229266
public static function array_strip_tags($array) {
    $result = array();

    foreach ( $array as $key => $value ) {
      $key = strip_tags($key);

      if (is_array($value)) {
        $result[$key] = self::array_strip_tags($value);
      } else if (is_numeric($value) && !preg_match('/^0\d+$/', $value)) {
        $result[$key] = $value + 0;
      } else {
        $result[$key] = htmlspecialchars(trim(strip_tags($value)), ENT_QUOTES | ENT_HTML5);
      }
    }

    return $result;
  }
220368
def strip_tags(cls, html):
        
        s = cls()
        s.feed(html)

        return s.get_data()
206414
public static function removeEmptyLines($html) {
    // merge multiple linebreaks to one
    $html = preg_replace("/(<br>\s*)+/", "<br>", $html);
    // remove linebreaks at the beginning of a paragraph
    $html = preg_replace("/<p>(\s|<br>)*/", "<p>", $html);
    // remove linebreaks at the end of a paragraph
    $html = preg_replace("/(\s|<br>)*<\/p>/", "</p>", $html);
    // remove empty paragraphs
    $html = preg_replace("/<p><\/p>/", "", $html);
    return $html;
  }
572616
public static function stripTags($html, $allowable = [])
    {
        if (!is_array($allowable)) {
            $allowable = preg_split("/, */", $allowable, -1, PREG_SPLIT_NO_EMPTY);
        }

        if ($allowable) {
            return strip_tags($html, '<' . implode('><', $allowable) . '>');
        }

        return strip_tags($html);
    }
261248
public function strip($string, $html = false) {
        return $this->getDecoda()->reset($string)->strip($html);
    }
233870
public function transform($html)
    {
        if (class_exists('HTMLPurifier')) {
            $config = HTMLPurifier_Config::createDefault();
            $purifier = new HTMLPurifier($config);
            $cleanHtml = $purifier->purify($html);
        } else {
            $cleanHtml = strip_tags($html, '<a><b><br><i><p><s><u>');
        }

        return $cleanHtml;
    }