How to show source codes on screens as help sites?

Asked

Viewed 260 times

2

How to register and show fonts on screen as on this site?

I’m creating a website 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 on screen, but it runs inside the database.

1 answer

3

To escape php source code and give a Highlight, use the function highlight_string(), to save the return in a pass variable true as a 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

Browser other questions tagged

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