title: CKEditor - how to save and display html code in rich text
body: <p>I had html textarea's with plain text, there are html code samples stored in MySQL.</p>
  
  <p>I changed textarea's to ckeditor class. All is fine, but all html code blocks are not displayed now in rich text mode.</p>
  
  <p>I've tried to use <code>&lt;pre&gt;</code> and <code>&lt;code&gt;</code> tags, but they are don't work.</p>
  
  <p>Also I tried insertpre plugin, and it doesn't help.</p>
  
  <p>Is there a way to display/save html code in CKEditor? How to ignore html tags in the block like on this site with Code Sample button?</p>
  
  <p><strong>My example.</strong>(Sorry, have no permissions to post images yet).</p>
  
  <p>Textarea field:</p>
  
  <p><code>&lt;textarea class="ckeditor" name = "description" &gt;Text&lt;/textarea&gt;</code></p>
  
  <p>I'm pasting code using "Insertpre" addon:</p>
  
  <pre><code> &lt;table border="1"&gt;
     &lt;tr&gt;
       &lt;td&gt;100&lt;/td&gt;
     &lt;/tr&gt;
   &lt;/table&gt;
  </code></pre>
  
  <p>At once I see correct picture.</p>
  
  <p>After form submit I get variable:
  <code>$description=$_POST['description'];</code> and put it to database.</p>
  
  <p>In database I see next value for this variable:</p>
  
  <pre><code>&lt;pre class="prettyprint"&gt;
  &amp;lt;table border=&amp;quot;1&amp;quot;&amp;gt;
  &amp;lt;tr&amp;gt;
    &amp;lt;td&amp;gt;100&amp;lt;/td&amp;gt;
  &amp;lt;/tr&amp;gt;
  &amp;lt;/table&amp;gt;&lt;/pre&gt;
  </code></pre>
  
  <p>html form which displays data from base:</p>
  
  <p><code>&lt;textarea class="ckeditor" name = "description" &gt;&lt;?php echo $description ?&gt;&lt;/textarea&gt;</code></p>
  
  <p>When I open this form, I see empty code block, all html code is outside of pre-block, and I see a real table instead of html tags.</p>
  
  <p>If I click on “Source” button , I see the same – table tags are not inside “pre” tags:</p>
  
  <pre><code>&lt;pre class="prettyprint"&gt;
  
  &amp;nbsp;&lt;/pre&gt;
  
  &lt;table border="1"&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;100&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>As I understand, code saved in database in correct format, so problem somewhere in the output or in CKEditor behavior...</p>
  
  <p><strong>Update: Found workaround:</strong>
  After long search I found similar problem in this topic: <a href="http://ckeditor.com/forums/CKEditor-3.x/html-code-pre-tags-problem" rel="nofollow">http://ckeditor.com/forums/CKEditor-3.x/html-code-pre-tags-problem</a>
  Described workaround helped me: if I make output with <em>htmlspecialchars</em> php function it works good:</p>
  
  <p><code>&lt;textarea class="ckeditor" name = "description" &gt;&lt;?php echo htmlspecialchars($description) ?&gt;&lt;/textarea&gt;</code></p>
  
  <p>I'm not sure is it a workaround or correct solution - after this all tags inserted in rich mode are displayed even without "pre" block. If yes - it should be in CKEditor FAQ, because this is very confusing.</p>