Skip to content

Instantly share code, notes, and snippets.

@web64
Created August 2, 2017 08:57
Show Gist options
  • Save web64/b0efa3f001401950f26fb72f5eff8674 to your computer and use it in GitHub Desktop.
Save web64/b0efa3f001401950f26fb72f5eff8674 to your computer and use it in GitHub Desktop.
<?php
function stripHtmlTags( $html )
{
$html = preg_replace('/<script\b[^>]*>(.*?)<\/script>/is', "", $html);
$html = preg_replace('/<style\b[^>]*>(.*?)<\/style>/is', "", $html);
$html = str_replace("<", " <", $html);
$html = strip_tags($html);
$html = preg_replace('/\x20+/', ' ', $html);
$html = str_replace(" ", " ", $html);
$html = str_replace("\n ", "\n", $html);
$html = preg_replace("/\n+/", "\n", $html);
return trim($html);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment