adjusting the way the regex is done so its easier to read

This commit is contained in:
dogmatic69 2012-09-13 06:30:15 +01:00
parent 25b447149d
commit 50333a2866

View file

@ -150,10 +150,15 @@ class Sanitize {
* Strips scripts and stylesheets from output * Strips scripts and stylesheets from output
* *
* @param string $str String to sanitize * @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) { 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); return preg_replace($regex, '', $str);
} }