Created
September 26, 2023 17:57
-
-
Save Lenny4/0bf3370ffba7b833ff76fe4017fa0a48 to your computer and use it in GitHub Desktop.
Match all html tag except `<s></s>` and `<strong></strong>`
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
### Match all html tag except `<s></s>` and `<strong></strong>` : | |
- `<(?!\/?(s|strong)(?=>|\s.*>|\/>))\/?.*?>` | |
- source : https://stackoverflow.com/questions/29869/regex-to-match-all-html-tags-except-p-and-p#answer-2928149 | |
- php | |
``` | |
<?php | |
function regexHtmlTags($string) | |
{ | |
$arrayTags = ["s", "strong", "em", "p"]; | |
$pattern = "/<(?!\/?(" . implode($arrayTags, '|') . ")(?=>|\s.*>))\/?.*?>/"; | |
return preg_replace_callback($pattern, function ($matches) { | |
return htmlspecialchars($matches[0]); | |
}, $string); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment