PHP does not generating output as html

In many cases we add content in the database with replacing all html tags into special characters. But it generate problems when we want to show at front side. So here we are giving a best solution to show result as HTML:

function __htmlConvertor($str)
{
$string = str_replace(array("<", ">", '&', ''', '"','<', '>'), array("<", ">",'&','\'','"','<','>'), htmlspecialchars_decode($str, ENT_NOQUOTES));

return $string;
}


Above function takes the string from the database (manually send)
and will return the code in the html format. Here are giving an example so you can understand in better way:

Before
&lt;div&gt;
naveenos group
&lt;/div&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;http://naveenos.com&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

 

After called to this function:

<div>
naveenos group
</div>
<table>
<tr>
<td>http://naveenos.com</td>
</tr>
</table>


Comments

Leave a Reply

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

*