How to convert html tags to string in PHP

By Admin - June 16, 2017 3:59 pm   2   259   0

In this article, i will tell you how to hide html special characters or html tags. When we use rich text editor in our CMS, we use many html tags in text editor but on front end, page showing html tags not design. So here s the solution.

We use htmlspecialchars_decode() to hide html tags and show design of that code. This function is used for convert the html special character to string.

1. Example :-

Code :-

$stringwithhtmltags = "This is <i>italic</i> text and this is <b>bold</b> text";
echo htmlspecialchars_decode($stringwithhtmltags);

Result : -

This is italic text and this is bold text

2. Example :-

Code :-

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Convert html tags to string</title>
<b>This is some text</b>
<i>This is some text</i>
<font color="blue">This is some text</font>

Result : -

This is some text This is some text
This is some text