Home > OS >  PHP adding a "\"s when trying to output html
PHP adding a "\"s when trying to output html

Time:10-04

I have a PHP Code that loads some HTML from the database and echo to my cpage, Problem is when I echo code the HTML becomes like this:

<div  itemscope="\&quot;\&quot;" itemtype="\&quot;https://schema.org/FAQPage\&quot;">
<div itemscope="\&quot;\&quot;" itemprop="\&quot;mainEntity\&quot;" itemtype="\&quot;https://schema.org/Question\&quot;" >
<h3 itemprop="\&quot;name\&quot;" >test quistion?</h3>
<div itemscope="\&quot;\&quot;" itemprop="\&quot;acceptedAnswer\&quot;" itemtype="\&quot;https://schema.org/Answer\&quot;">
<p itemprop="\&quot;text\&quot;" >Test answer</p>
</div>
</div>

My Code to echo HTML:

<?php
   $cat_data = get_option("category_$cat_id");
   if (isset($cat_data['faq'])){
      echo $cat_data['faq'];
   } } ?>

CodePudding user response:

It works with this:

 echo stripslashes($cat_data['faq']);

thanks to @numediaweb How save JavaScript and HTML in option without it being auto-escaped?

CodePudding user response:

Try this:

<?php
     $cat_data = get_option("category_$cat_id");
     if (isset($cat_data['faq'])){
     echo html_entity_decode($cat_data['faq'], ENT_QUOTES, 'UTF-8');
     } } ?>
  • Related