Version 1 (modified by gogo, 13 years ago) (diff)


Entize Your Data

When you put HTML into a textarea to be turned into a Xinha editor, many people forget that raw HTML in a textarea is not valid HTML, this leads to all sorts of unusual symptoms.

The TEXTAREA tag accepts #PCDATA, that means its plain character data which can include entities for the special characters, you should not put HTML into the textarea, while some browsers will allow you to get away with most HTML, it will break at some point.

The Wrong Way

This is the wrong way, you will see that the HTML to be edited has been put into the textarea without any entitization, i.e the raw html has been inserted.

  <textarea name="MyXinha">
    <h1>G'Day &amp; Welcome</h1>
    <a href="">Hello World</a>

The Right Way

This is the right way, the HTML to be edited has been entized before it was put into the textarea, < is now &lt; > is &gt; and " is &quot; and & is &amp;

  <textarea name="MyXinha">
    &lt;H1&gt;G'Day &amp;amp; Welcome&lt;/h1&gt;
    &lt;a href=&quot;;&gt;Hello World&lt;/a&gt;

Language Specific Methods


Use the PHP function htmlspecialchars(), eg

  <textarea><?php echo htmlspecialchars($HtmlToEdit) ?></textarea>


Use the function HTMLEditFormat(), eg