Search code examples
phpmysqlstringvarchar

output varchar with html tags from sql - output is encoded and should not be


Saving input from a form field into sql database varchar(255)... The input would be something like :

<a href="test.com">Author Name</a>

Bottom line is it will more than likely have html tags in it most of the time. When I retrieve and output from the database I get something like :

&lt;a href=&quot;test.com&quot;&gt;Author Name&lt;/a&gt;

As this should be echo'ed as html it does not show properly on the page. Maybe I am just tired, but I cannot figure out how to output this as non-encoded so it is properly read by the browser.


Solution

  • Try this:

    <?php
        echo htmlspecialchars_decode("&lt;a href=&quot;test.com&quot;&gt;Author Name&lt;/a&gt;");
    ?>
    

    Why do you encode the html tags before inserting into the database?