Merge pull request #831 from dogmatic69/sanitize-regex-cleanup

adjusting the way the regex is done so its easier to read
This commit is contained in:
Mark Story 2012-09-13 14:41:36 -07:00
commit 31ca237709

View file

@ -150,10 +150,15 @@ class Sanitize {
* Strips scripts and stylesheets from output
*
* @param string $str String to sanitize
* @return string String with <script>, <style>, <link>, <img> elements removed.
* @return string String with <link>, <img>, <script>, <style> elements and html comments removed.
*/
public static function stripScripts($str) {
$regex = '/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|<img[^>]*>|style="[^"]*")|<script[^>]*>.*?<\/script>|<style[^>]*>.*?<\/style>|<!--.*?-->/is';
$regex =
'/(<link[^>]+rel="[^"]*stylesheet"[^>]*>|' .
'<img[^>]*>|style="[^"]*")|' .
'<script[^>]*>.*?<\/script>|' .
'<style[^>]*>.*?<\/style>|' .
'<!--.*?-->/is';
return preg_replace($regex, '', $str);
}