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:
to Pakainfo"; //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
Example 2:
Welcome to Pakainfo.com.Hello to everyone Guys "; $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.