-
-
Save dead23angel/0f03dd12aff9341d3b65 to your computer and use it in GitHub Desktop.
extended laravel escaping with exclusion some tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* use in blade template `{!! ex($message, ['br', 'strong']) !!}` | |
*/ | |
if (!function_exists('ex')) { | |
function ex($str, array $excluded) | |
{ | |
$patterns = $tags = []; | |
foreach ($excluded as $ex) { | |
$open_tag = '<' . $ex . '>'; | |
$close_tag = '</' . $ex . '>'; | |
$patterns[] = '~' . preg_quote(e($open_tag), '~') . '~'; | |
$tags[] = $open_tag; | |
$patterns[] = '~' . preg_quote(e($close_tag), '~') . '~'; | |
$tags[] = $close_tag; | |
} | |
return preg_replace($patterns, $tags, e($str)); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment