Show PHP code on site without PHP executing the code

I need to show code on my site. How can I show PHP code without it being executed?

Do I just change the < and > in <?php and ?> to html entities?

Also, I guessing ellislab.com build their site with CodeIgniter
http://ellislab.com/codeigniter/user-guide/tutorial/news_section.html

They show PHP code, but the URL is .html. How do they do that?

Is this probably a PHP page but being server as .html, is that even possible?

Thanks

you can use,


highlight_file('file_name');

or


<?php

    $code =  '<?php
                $lista = array("joão", "maria", "josé");
                foreach($lista as $item){
                    echo $item  ."<br>";
                }';

echo '<pre>' . htmlspecialchars($code) . '</pre>';

[joke]
maybe will ‘work’ if you use open_short_tag <?= ?> lol
[/joke]

Pretty much. But normally you’d also wrap the code in <code> tags, and then wrap those in <pre> tags to preserve the formatting.

Is this probably a PHP page but being server as .html, is that even possible?

You can run PHP on .html pages by changing your settings (normally in a .htaccess file).

There’s also this library: http://qbnz.com/highlighter/