How to easily display PHP/HTML codes in your webpages
If you want your visitors to be able to see the source codes of your webpage, there is a very easy way to do so. Normally, all you have to do in a HTML file using IE is to go in the View option on your taskbar and then select Source.
Another simple way to do that is to insert the codes below in the PHP or HTML file so that those who wish to get the codes to build their own website or alter their websites’ display.
What code to use?
If you want to display the code of your index file (index.php), all you have to do is to insert
highlight_file(index.php);
in the body of the document.
One other way to do it is to use the constant __FILE__. You should however use the exit function to avoid displaying the rest of the script. This is very helpful to avoid displaying a protected document enclosing a username and password.
Here is a full code that you can make use of to be able to display the code correctly. You can insert it after your body tag:
afficher_code_php function ()
(
if (isset ($ _GET [ 'source']))
(
echo '<a <p> href="',$_SERVER['PHP_SELF'],'"> Back </ a> </ p>';
echo '<p> This is the code php file: </ p>';
$ page = highlight_file ($ _SERVER [ 'SCRIPT_FILENAME'], TRUE);
$ page = str_replace (
array ( '<code>', '/ code>', '','</ are >','< font color ="'),
array ( '<pre style="padding:1em;border:2px solid black;overflow:scroll">', '/ pre>', '','</ span >','< span style = "color:' ), $ page);
echo $ page;
echo '<a <p> href="',$_SERVER['PHP_SELF'],'"> Back </ a> </ p>';
echo '</ body> </ html>';
exit;
)
)