How to easily display PHP/HTML codes in your webpages

Last update on October 17, 2009 02:58 PM by jak58
Published by aakai1056

How to easily display PHP/HTML codes in your webpages





Issue


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:


display_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; 
       ) 
   )
Best answers for « How to easily display PHP/HTML codes in your webpages » in :
[PHP]antispam code with numbers and letters (CAPTCHA) Show [PHP]antispam code with numbers and letters (CAPTCHA) On many sites, the forms are accompanied by an insert request to copy a randomly generated code. Such a system called CAPTCHA, used to limit abusive automated mailings (SPAM)....
Publish a PDF file on your website ShowPublish a PDF file on your Website Displaying a link to a PDF on your Website Displaying the PDF on your website Displaying a link to a PDF on your Website Proposing a PDF link on your own website is an operation that can seem...
Remove the underline under the links in HTML/CSS ShowRemove the underline under the links in HTML/CSS Using CSS Using CSS via a class Using CSS online AS you may have noticed, hyperlinks are underlined in HTML (by default) It is possible to remove the underline by using the CSS Using...
Download Crimson Editor ShowCrimson Editor is a professional source code editor for Windows. This light program can be used to replace Windowd notepad. It offers numerous and powerful features to display the source code in the following languages: HTML, C/C ++, Perl and Java: ...
HTML Markup ShowHTML, A Markup Language HTML is not a programming language. Rather, it is used for describing the layout and format of content, written in the form of simple text. An HTML page is a basic text file containing tags for specifying text format,...
Frames ShowIntroduction to Frames You can display multiple HTML pages in different areas at once. These areas are called frames. Frames are not found in the specifications of HTML 3.x, so the Document Type Declaration must show the page as having been...
Declaring a style sheet (CSS) ShowDeclaring a style sheet Style sheets are not directly integrated into the W3C's HTML recommendations. For this reason, you need to include elements in the HTML code indicating both the type of document, meaning the version of the HTML and CSS...