How to display HTML code from database using PHP and preventing the browser from interpreting the code.

Posted on 2007-03-20
Last Modified: 2012-05-05
I have html code contained in a database (MySQL) of code maintenance information.  I want to be able to display the html code without having the code interpreted.

Is there a php function to encode the html so that it displays as text (showing all of the tags)?  Or is there an HTML tag set that stops the interpretation of content between tags?

Question by:ttheimer
  • 2
  • 2
LVL 20

Expert Comment

ID: 18759830

<textarea cols="90" rows="30">
<? echo $html ?>


Author Comment

ID: 18760007
Textarea produces a fixed-size input field.  Not a good fit for displaying database contents (essentially an on-screen report).
LVL 20

Accepted Solution

steelseth12 earned 125 total points
ID: 18760371

print htmlentities($html);

Author Comment

ID: 18760696
That's what I needed!  The report now prints cleanly.  Thanks.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

932 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

10 Experts available now in Live!

Get 1:1 Help Now