user4659577
user4659577

Reputation:

Convert string to HTML elements php


I am storing html code in wordpress database.
For eg: <i>Some text</i>;

It is recognized as string when I fetch it. How to convert it into HTML code?

I cannot change the database field type. Please help.
Thanks in advance

Upvotes: 1

Views: 5897

Answers (1)

Julian Dasilva
Julian Dasilva

Reputation: 76

I will assume you are trying to display the html code and that's why you'd like to convert it into html. In PHP when you want to display some html code instead just use the echo command to display the code inside of your html and use the htmlspecialchars_decode function to ensure it will work properly. For example see below:

<?php
//some database call here to get our string seen below

$database_string ='<i>Some text</i>;
?>
<html>
<?php echo  htmlspecialchars_decode($database_string); ?>

<!-- some other html stuff -->

</html>

This will allow you to display that I tag with the some text inside the html.

Upvotes: 1

Related Questions