Home PHP How to display code as content using PHP as your programming language?
 
 
 

How to display code as content using PHP as your programming language?

PDF Print E-mail

Question: How to display code as content using PHP as your programming language?

 

Example: I have the following JavaScript code that I need to display as plain content on a page and when I add it the page handles it as code instead of content.

 

The code below I need to display as content

<script src="fancybox/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>

 

Answer:

  • Use the 'htmlspecialchars' PHP function tdisplay the code as content
    • htmlspecialchars - Convert special characters to HTML entities (PHP 4 & 5)
  • See the example below

    htmlspecialchars('<script src="fancybox/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>');
    
  • The code above will display the below as content

     <script src="fancybox/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
     
+/-
+/- Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security Please input the anti-spam code that you can read in the image.
 
 
Banner