View code on page

Asked

Viewed 537 times

2

What tag do I use to display any code on the page? That is, how do I display codes PHP or any other on the page in such a way that the browser reads it as text and does not interpret it as code?

2 answers

1


Have to use < and > (HTML Entities), something like:

<pre>
&lt;?php
    
echo 'Olá';
<pre>

You can make it easier by using the function htmlspecialchars of PHP itself, for example, assuming that it will read a script and display it:

<pre>
<?php
$dados = file_get_contents('script.php');
echo htmlspecialchars($dados);
?>
</pre>

Enjoy and read about some differences: What is the difference between htmlspecialchars() and htmlentities()?

0

Browser other questions tagged

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