HTML does not run when inside a PHP variable

Asked

Viewed 182 times

0

Good morning friends.

I’m returning an html code through the BD in php, when I echo the variable instead of running the html code it displays as if it were a text someone knows how to help me?

From now on, thank you

<div class="papel" id="papel" style="margin-top:calc(297mm * <?php echo $i?>)!important;background-color:<?php echo $cor ?>">
<?php    
    $listagem = new Consulta();
    $listagem->Conecta();
    $retorno = $listagem->ConsultaDados('cf_codigo', 'dm_id', 'ASC','dm_id=71');
    if(count($retorno) > 0) {
        foreach ($retorno as $linha) {
        // Ao executar essa linha, ao inves do codigo html na variavel ser executado, é é escrito.
            echo $linha->dm_codhtml;
        }
    }
?>
</div>

Upshot:

inserir a descrição da imagem aqui

  • 1

    Put in the code you already have

  • 1

    Hi Anderson! Can you [Edit] the question and join the code you refer to?

  • @Sergio added the code and an image, I believe that facilitate understanding.

  • 3

    @Anderson, what’s wrong with putting the code in text? So we can use the code in the answer, without it (or as an image) is much more difficult and makes us waste more time to help you...

  • A similar problem happened to me, so I solved it.(Adapting to your example) echo "{$line->dm_codhtml}";

  • You could try that code? echo addslashes($linha->dm_codhtml); or <<<HTML echo $linha->dm_codhtml HTML; ?

  • Pedrofranco and Rafaelwithoeft thank you, I tried both but without success. Both appear the same code identical to figure.

  • The html presentation by php, not provided by the database <?php echo <span>teste</span>; ?> works normally? Or both are displaying the html code on the screen as a text?

  • @Rafaelwithoeft performed the test and apparently the problem is when the variable is displayed with database data... <?php echo "<span>teste</span>"; ?> This way is executed correctly,

  • @Did Anderson solve it? Would you like to take a closer look at your code, is there another way to contact so I can help you? Email?

  • Hello, thank you very much. I haven’t got it yet, I’m trying, my email is [email protected]

Show 6 more comments

1 answer

5

The HTML code is coming encoded from the database. You need to unmode it.

Instead of doing like this:

echo $linha->dm_codhtml;

... do so:

echo html_entity_decode($linha->dm_codhtml);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.