Reputation: 233
I have a application where I store sting as it is but while dispying, I want special characters to be converted to their HTML name like for <
will be <
. To achieve it, I am using php inbuilt function htmlspecialchars.
Output of text with this function is achieved with following code
$reviewTxt = htmlspecialchars($reviewTxt);
echo $reviewTxt;
Now, for reviewTxt to be 'I loved you <3', it should produce I loved you <3
but should display the original text. In my case, it displays the encoded data I loved you <3
. I also tried to paste I loved you <3
instead of above php code just to see if I can get original text and yes, it shows 'I loved you <3'.
I am not sure what I am missing,
Upvotes: 1
Views: 160
Reputation: 91734
It looks like you are encoding twice with htmlspecialchars()
/ htmlentities()
.
That causes the &
symbol of the first result to be encoded in the second result, giving you a string like I loved you &lt;3
.
So it will show the encoded &
followed by the litteral string lt;
.
Upvotes: 1