Remove Html tags from string PHP – PHP strip_tags() Function

Remove Html tags from string PHP – PHP strip_tags() Function

Today, We want to share with you Remove(Delete) Html tags from string PHP – PHP strip_tags() Function.In this post we will show you wordpress plugin require another plugin, hear for php remove style tag and content, we will give you demo and example for implement.In this post, we will learn about remove script tags from string php with an example.

Remove Html tags from string PHP – PHP strip_tags() Function

There are the Following The simple About Delete Html tags from string PHP – PHP strip_tags() Function Full Information With Example and source code.

As I will cover this Post with live Working example to develop PHP Function to remove specified html tags from string, so the how to remove html tags in php from mysql, is used for this example is following below.

Read Also:  how to check a plugin is activated or not in wordpress

Simple PHP strip_tags() Function



world!“);
?>

This function strips a string from HTML, XML, and PHP tags. In this example, the tag gets stripped.


Remove all html tags from php string

using PHP strip_tags

$data_text = '<p>Test paragraph.</p><!-- Comment --> <a href="#product_desc">Other text</a>';
echo strip_tags($data_text);   //output Test paragraph. Other data_text

<?php echo substr(strip_tags($products['description_description']),0,110) . "..."; ?>

Remove HTML Tags from String using PHP

Use Simple strip_tags( ) to remove HTML and PHP tags from a data strings: Below Examples

Remove all Tags

<?php

$data_str = "<p>HDMoives</p><b> TamilRokers</b><i> by TamilMv</i>";

echo strip_tags($data_str, "<b><i>");

?>

Output

HDMoives<b> TamilRokers</b><i> by TamilMv</i>

Remove all Tags with inner Content

<?php

    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; 
    } 

    $data_str = "<p>HDMoives</p><b> TamilRokers</b><i> by TamilMv</i>. Thanks for watching";

    echo strip_tags_content($data_str, "<b><i>");

?>

Output

<b> TamilRokers</b><i> by TamilMv</i>. Thanks for watching

Remove Certain Tags

<?php

    $data_str = "<p>HDMoives</p><b> TamilRokers</b><i> by TamilMv</i>. Thanks for watching";
    $tags = array("p", "i");

    foreach($tags as $tag)
    {
        $data_str = preg_replace("/<\\/?" . $tag . "(.|\\s)*?>/", $replace_with, $data_str);
    }

    echo $data_str;
?>

Output

HDMoives<b> TamilRokers</b> by TamilMv. Thanks for watching

Remove Certain Tags with Content

<?php

    $data_str = "<p>HDMoives</p><b> TamilRokers</b><i> by TamilMv</i>. Thanks for watching";
    $tags = array("p", "i");

    echo preg_replace('#<(' . implode( '|', $tags) . ')(?:[^>]+)?>.*?</\1>#s', '', $data_str);

?>

Output

<b> TamilRokers</b>. Thanks for watching

Web Programming Tutorials Example with Demo

Read :

Read Also:  how to remove html tags in php from mysql?

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.


I hope you get an idea about Delete Html tags from string PHP – PHP strip_tags() Function.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.