| 1 | <?php |
||
| 14 | final class HtmlFilter |
||
| 15 | { |
||
| 16 | // Return the entire string as-is |
||
| 17 | public const ALLOW = 'allow'; |
||
| 18 | // Escape the entire string so any HTML/JS won't be interpreted as such |
||
| 19 | public const ESCAPE = 'escape'; |
||
| 20 | // Return an empty string |
||
| 21 | public const STRIP = 'strip'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Runs the given HTML through the given filter |
||
| 25 | * |
||
| 26 | * @param string $html HTML input to be filtered |
||
| 27 | * @param string $filter One of the HtmlFilter constants |
||
| 28 | * |
||
| 29 | * @return string Filtered HTML |
||
| 30 | * |
||
| 31 | * @throws \InvalidArgumentException when an invalid $filter is given |
||
| 32 | */ |
||
| 33 | 285 | public static function filter(string $html, string $filter): string |
|
| 46 | } |
||
| 47 |