Skip to content

Instantly share code, notes, and snippets.

@dead23angel
Forked from Ellrion/helpers.php
Created February 10, 2016 15:49
Show Gist options
  • Save dead23angel/0f03dd12aff9341d3b65 to your computer and use it in GitHub Desktop.
Save dead23angel/0f03dd12aff9341d3b65 to your computer and use it in GitHub Desktop.
extended laravel escaping with exclusion some tags
<?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