Show textarea code

0

What I intend and show on my web site inside a textarea code php html and etc but whenever I try to do it runs the code and I want it to show inside a text area or another system and any such as here no stack overflow

<section class="bg-light" id="links">
  <div class="container">

    <h1 class="text-center text-info">Teste PHP</h1>

      <?php
          echo"Olá, Mundo!";
          echo("<h2>Olá, Mundo</h2>");
          ?>

    </div>
  </div>

</section>
<section class="bg-light">
  <hr></hr>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <label for="comment" class="text-info">Código feito:</label>
        <textarea class="form-control" rows="15" id="codigo">Conteudo a apresentar</textarea>
    </div>
    </div>
  </div>
</section>
    
asked by anonymous 24.10.2017 / 23:26

1 answer

0

You need to encode all html entities. Most languages already have some automatic way of escaping the code.

In Java, using JSTL in the JSP, you can do this:

<c:out value="${valorAqui}" escapeXml="true"/>

In PHP, there is the htmlentities function that you use:

<?php echo htmlentities($texto); ?>

I did not get to this, but I believe that in a simple way you could also print the php code as follows within HTML:

<?php echo '<?php //aqui você insere seu código... ?>' ?>

See:

<section class="bg-light" id="links">
  <div class="container">

    <h1 class="text-center text-info">Teste PHP</h1>

      <?php
          echo"Olá, Mundo!";
          echo("<h2>Olá, Mundo</h2>");
          ?>

    </div>
  </div>

</section>
<section class="bg-light">
  <hr></hr>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <label for="comment" class="text-info">Código feito:</label>
        <textarea class="form-control" rows="15" id="codigo"><?php echo htmlentities($conteudoParaApresentar); ?></textarea>
    </div>
    </div>
  </div>
</section>
    
24.10.2017 / 23:45