Display code on page

2

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

    
asked by anonymous 06.04.2018 / 16:30

2 answers

1

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

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

You can make this easier by using the htmlspecialchars function of PHP itself, for example, assuming you are going to 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's the difference between htmlspecialchars () and htmlentities ()?

    
06.04.2018 / 16:32
0

I do not know if I understand 100% but it looks like you're looking for something like the highlight_file function.

link

Example usage: highlight_file ('myFile.php');

    
06.04.2018 / 16:44