Reputation: 4682
I need to display a few item names as it is stored in database. It is working fine except when the name contains HTML special characters. For eg: if the name is like <ItemName>
it is showed as <ItemName>
when echo it using PHP. How can I prevent this. Also if the name is stored in DB as <ItemName>
it should show like that only. When I tried to use htmlentities()
, it is showing the &
as &
and that isn't what I need to show. How this can be fixed ?
Also I am using Highcharts and it has the item names as labels. So the name <ItemName>
(if with tags), needs to be converted to htmlentities()
in order to display it correctly. Otherwise, it will not show the label.
Upvotes: 1
Views: 118
Reputation: 13303
Just use htmlspecialchars function
<?php
echo(htmlspecialchars('<ItemName>something</ItemName>'));
or as in your case:
<?php
echo(htmlspecialchars('<ItemName>something</ItemName>'));
Upvotes: 2