Remove all tags with internal content

I want to remove all tags with internal content.

I am using the following function.

function strip_tags_content($text, $tags = '', $invert = FALSE) {

    preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
    $tags = array_unique($tags[1]);

    if (is_array($tags) AND count($tags) > 0) {
        if ($invert == FALSE) {
            return preg_replace('@<(?!(?:' . implode('|', $tags) . ')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
        } else {
            return preg_replace('@<(' . implode('|', $tags) . ')\b.*?>.*?</\1>@si', '', $text);
        }
    } elseif ($invert == FALSE) {
        return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
    }
    return $text;
}

But I still get the following result.

<p><span style="color: rgb(38, 38, 38); font-family: arial, helvetica, sans-serif; fon...

I want all html tags to be removed.

p, span etc. Where am I mistaken?

+4
source share
1 answer

You can use the built-in function PHP's PHP's.

$striped_string = strip_tags($your_html_string);

NOTE. . In addition, you can also make sure that certain tags are not split by passing these tags as the second parameter

Take a look at PHP DOCS

0
source

All Articles