PHP - Variable value not printing as html

user3531660

I am trying to print php variable which contains html tag in it. I want to display it as html but it is print it as plain text. Below is my code:

$final= $first . $second . $third;
echo $final;
echo htmlentities($final);
echo htmlspecialchars($final);

$first value is <iframe

$second value is width="960" height="540"

$third value is src="" allowfullscreen="true"></iframe>

so $final combine string of all 3 variable which I intend to display it as an iframe. But it just display text as below:

<iframe width="960" height="540" src="" allowfullscreen="true"></iframe>
Eduardo Villalobos

I think that it's happening because you are using the incorrect method htmlentities OR htmlspecialchars. Remember that those methods converts HTML into characters. If you want to print the HTML from String, you need to use html_entity_decode.

echo html_entity_decode($final);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related