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

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:  laravel soft delete relationship Eloquent ORM

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

Read Also:  Laravel Soft Delete Example Tutorial From Scratch

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.*?>.*?</>@si', '', $text); 
            } 
            else 
            { 
                return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</>@si', '', $text); 
            } 
        } 
        elseif($invert == FALSE) 
        { 
            return preg_replace('@<(\w+)\b.*?>.*?</>@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) . ')(?:[^>]+)?>.*?</>#s', '', $data_str);

?>

Output

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

Web Programming Tutorials Example with Demo

Read :

Read Also:  Check WordPress Plugin Dependencies

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.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  ng-options to Set Default Value using Angular Example
  2. Read Also:  Auto Post on Facebook Page using Facebook PHP API
  3. Read Also:  how to split a string in python? | python split string into list
  4. Read Also:  Laravel get multiple checkbox value From View to Controller
  5. Read Also:  Laravel requires the Mcrypt PHP extension
  6. Read Also:  MySql comma separated column join using PHP Laravel
  7. Read Also:  Image Crop and Upload using jQuery and PHP
  8. Read Also:  Laravel Soft Delete Example Tutorial From Scratch
  9. Read Also:  Check WordPress Plugin Dependencies
  10. Read Also:  Laravel get multiple checkbox value From View to Controller

Leave a Comment

Your email address will not be published. Required fields are marked *