Skip to content

Instantly share code, notes, and snippets.

@MilkZoft
Created January 18, 2012 04:00
Show Gist options
  • Select an option

  • Save MilkZoft/1630853 to your computer and use it in GitHub Desktop.

Select an option

Save MilkZoft/1630853 to your computer and use it in GitHub Desktop.
codejobs - Clean HTML from a string - PHP
<?php
function cleanHTML($HTML) {
$search = array ('@<script[^>]*?>.*?</script>@si',
'@<[\/\!]*?[^<>]*?>@si',
'@([\r\n])[\s]+@',
'@&(quot|#34);@i',
'@&(amp|#38);@i',
'@&(lt|#60);@i',
'@&(gt|#62);@i',
'@&(nbsp|#160);@i',
'@&(iexcl|#161);@i',
'@&(cent|#162);@i',
'@&(pound|#163);@i',
'@&(copy|#169);@i',
'@&#(\d+);@e');
$replace = array('',
'',
'\1',
'"',
'&',
'<',
'>',
' ',
chr(161),
chr(162),
chr(163),
chr(169),
'chr(\1)');
$text = preg_replace($search, $replace, $HTML);
return $text;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment