Question:
I'm translating a book to an HTML page, there are codes in the book, but how can I make my HTML display my code, HTML, PHP and JavaScript, without executing them?
Answer:
You need to escape the characters that cause your tags to be interpreted as HTML, the <
and >
.
For example, instead of:
<div>Teste</div>
use:
<div>Teste</div>
If you are using PHP, there is a function that does this, htmlentities
:
echo htmlentities('<div>Teste</div>');
In the case of PHP code, just output it without the initial <?php
, and it won't be interpreted. If you want to include <?php
in the example, use <?php
.