Show code on your site, so they can copy it.

Posted on 2007-11-19
Last Modified: 2010-04-21

I want to show this code in a frame or table so people can copy it and use it on there own site.

How to show code on a php page??

<!-- Start 468x60 Banner -->
      <a border="0" href=""><img src="" alt="MyAlt Text" border=0></a>
<!-- Einde 468x60 Banner -->
Question by:HPvH
LVL 49

Assisted Solution

Roonaan earned 60 total points
ID: 20311424
You can use htmlspecialchars() to escape your tags:

echo htmlspecialchars($code);

To replace newlines with <br /> tags as well you can use:

echo nl2br(htmlspecialchars($code));

LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 20311551
better use <iframe>...</iframe> to display something like this info as table or grid section like... some cool examples at

Author Comment

ID: 20311704
I need a code that shows the code on a page so a person can cody the code and use it.


<div class="phpcode"><code><span class="html">
&lt;html&gt;<br />
 &lt;head&gt;<br />
   &lt;title&gt;Voorbeeld&lt;/title&gt;<br />
 &lt;/head&gt;<br />
 &lt;body&gt;<br />
<br />
   <span class="default">&lt;?php <br />
   </span><span class="keyword">echo </span><span class="string">"Hallo! Ik ben een PHP script!"</span><span class="keyword">; <br />
   </span><span class="default">?&gt;<br />
</span><br />
 &lt;/body&gt;<br />

Accepted Solution

palanee83 earned 65 total points
ID: 20312275
yes you can like below

$codeToSHow=' <a border="0" href=""><img src="" alt="MyAlt Text" border=0></a>';

echo (htmlspecialchars($codeToSHow)

it will work

Author Closing Comment

ID: 31409905

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now