how to remove html tags in php from mysql?

Today, We want to share with you php remove html tags.In this post we will show you php strip specific tags, hear for PHP strip_tags() Function we will give you demo and example for implement.In this post, we will learn about PHP strip_tags() with an example.

PHP – How to Remove HTML Tags From a String?

Predefined Method

Example 1:

<?php
//declaring a string with html tags
$html_string="Welcome <span>to</span> <b>Pakainfo</b>";
//display the sting without any html tags
echo strip_tags($html_string);
?>


Welcome to Pakainfo.com

Userdefined Method

first of all declaring a string using Heredoc method and then calling the remove_html_tags function with the necessary html tags you want to remove as well as To avoid executing rest tags it is converted to normal text and display the result

Read Also:  PHP Ajax Autocomplete Search from Database Example

Example 2:

<?php

$string = "<span>Welcome <i>to</i> Pakainfo.com.</span><b>Hello to everyone Guys </b>";

$removed_str=remove_html_tags($string, array("span","b",'i'));

echo htmlentities($removed_str);
    
function remove_html_tags($string, $html_tags) 
{
    $tagStr = "";
  
        foreach($html_tags as $key => $value) 
        { 
            $tagStr .= $key == count($html_tags)-1 ? $value : "{$value}|"; 
        }
  
    $pat_str= array("/(<\s*\b({$tagStr})\b[^>]*>)/i", "/(<\/\s*\b({$tagStr})\b\s*>)/i");
    $result = preg_replace($pat_str, "", $string);
    return $result;
}
?>

Welcome to Pakainfo.com.Hello to everyone Guys

I hope you get an idea about Remove all html tags from php string.
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.