Remove all attributes from HTML tags in PHP 1

Remove all attributes from HTML tags in PHP

$text = '

Clean text

'; $cleanText = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/si",'<$1$2>', $text);

Here is what the above code is Doing:
1. The first part of the regular expression, <([a-z][a-z0-9]*)[^>]*?(\/?)>, matches the opening tag.
2. The second part of the regular expression, >, matches the closing bracket of the opening tag.
3. The third part of the regular expression, <\/\1>, matches the closing tag.
4. The fourth part of the regular expression, >, matches the closing bracket of the closing tag.

Similar Posts