1


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

7
  • 1
    <i>Some text</i> is html code Commented Feb 5, 2018 at 16:39
  • No. It displays as text in the front end. Commented Feb 5, 2018 at 16:39
  • How are you storing it, and how are you displaying it? Are you converting the data before you store it, so it looks like &lt;i&rt;? Commented Feb 5, 2018 at 16:40
  • 1
    Read the source of your HTML page. You'll see what is really written. Commented Feb 5, 2018 at 16:41
  • 1
    show the script or the page source before i vote your post down Commented Feb 5, 2018 at 16:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

could you use print_r($database_string) and tell me what is shown inside of that? There maybe an outside issue if you used the htmlspecialchars_decode.
Thanks for your reply. The output is still same. Please check the code ibb.co/buZiJx .
Sorry, I should have maybe been more clear. What does the print_r of that database string actually return to you when you run it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.