Last active
August 11, 2017 08:27
-
-
Save Ellrion/5810b9bb5593555a8348 to your computer and use it in GitHub Desktop.
Revisions
-
Ellrion revised this gist
Aug 11, 2017 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,5 @@ <?php if (!function_exists('ex')) { /** * Escape HTML entities in a string with exclusion some tags. @@ -14,10 +15,10 @@ function ex($str, array $excluded) $patterns = $tags = []; foreach ($excluded as $ex) { $allowed_tag_variants = [ '<' . $ex . '>', //open tag or single tag variant '</' . $ex . '>', //close tag '<' . $ex . ' />', //single tag variant '<' . $ex . '/>', //single tag variant ]; foreach ($allowed_tag_variants as $tag) { $patterns[] = '~' . preg_quote(e($tag), '~') . '~'; -
Ellrion revised this gist
Aug 11, 2017 . 1 changed file with 19 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,30 @@ <?php if (!function_exists('ex')) { /** * Escape HTML entities in a string with exclusion some tags. * * use in blade template `{!! ex($message, ['br', 'strong']) !!}` * * @param string $str * @param string[] $excluded * @return string */ function ex($str, array $excluded) { $patterns = $tags = []; foreach ($excluded as $ex) { $allowed_tag_variants = [ '<' . $ex . '>', //open tag '</' . $ex . '>', //close tag '<' . $ex . ' />', //single tag variant one '<' . $ex . '>', //single tag variant two ]; foreach ($allowed_tag_variants as $tag) { $patterns[] = '~' . preg_quote(e($tag), '~') . '~'; $tags[] = $tag; } } return preg_replace($patterns, $tags, e($str)); } } -
Ellrion revised this gist
Feb 10, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ <?php /** * use in blade template `{!! ex($message, ['br', 'strong']) !!}` */ if (!function_exists('ex')) { function ex($str, array $excluded) { -
Ellrion created this gist
Feb 10, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ <?php 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)); } }