How to display source codes on screens as help sites? [closed]

2

How do you register and display source codes on-screen like this site?

I'm creating a site where I register everything I develop as a library. But I want you to show the codes on the screen when I choose an article. I tried to register as if it were text and echo echo on screen, but it runs inside the database.

    
asked by anonymous 03.07.2015 / 20:17

1 answer

3

To escape php source code and highlight it, use the highlight_string () function. , to store the return in a variable pass true as the second argument.

<?php
$str = '<?php 
            $n1 = 10;
            $n2 = 5;
            echo $n1 + $n2;';

//Exibe o valor na tela 
highlight_string($str);

//Não exibe na tela
$code = highlight_string($str, true);

Example - phpFiddle

    
03.07.2015 / 20:22