How to convert html tags to string in PHP
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 :-

<?php
$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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Convert html tags to string</title>
</head>
<b>This is some text</b>
&nbsp;
<i>This is some text</i>
<div>
<font color="blue">This is some text</font>
</div>
<body>
</body>
</html>

Result : -

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



Comment