Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this the right way to deal with special characters in my CMS and front end?
    primarykey
    data
    text
    <p>I have battled with special characters in my CMS's for years and I'm still having a few problems. I have a very simple CMS which has textareas that allow you drop portions of HTML/content into them, then save to my database. </p> <p>I encounter problems (detailed below) when copying and pasting from MS Word into the CMS. For example, a curly apostrophe: <strong>’</strong></p> <p>I understand I am meant to be using UTF-8. I just want to confirm I am using the right approach.</p> <p>My CMS <code>&lt;HEAD&gt;</code> has the following:</p> <pre><code>&lt;meta http-equiv="content-type" content="text/html; charset=utf-8"&gt; </code></pre> <p>Stupidly my front end web pages <code>&lt;HEAD&gt;</code> have:</p> <pre><code>&lt;meta http-equiv="content-type" content="text/html;charset=iso-8859-1" /&gt; </code></pre> <p>And I've just noticed in config.php file (sits as a first include in my CMS), I have the following:</p> <pre><code>header("Content-Type: text/html; charset=iso-8859-1"); </code></pre> <p>When I save data to the DB from the textarea, I simply save it by doing:</p> <pre><code>mysql_real_escape_string($textarea) </code></pre> <p>When I load the data back to the textarea I do it by the following:</p> <pre><code>htmlspecialchars($this-&gt;cmsDb-&gt;html_body) </code></pre> <p>As it stands now (with the messy char set mixes), if I paste from MS Word and click save, the data enters into my DB - but it fails to load back into the textarea because htmlspecialchars() returns a blank string. I understand why that is - it can't load the unrecognised characters.</p> <p>So the real questions are: </p> <p>1) if I change the iso-8859-1 references to to UTF-8 - should everything be ok going forward? Or am I missing something else?</p> <p>2) Do I need to be very specific with any database / table encoding?</p> <p>3) Should special characters stay as special characters in my DB and when loading back into my text areas? Or should they all be in ASCII code format?</p> <p>BIG thank you to anyone that can help me work through this.</p> <pre><code>UPDATE!!! </code></pre> <p>I have no changed the charsets of the header() and the front end webpages to utf-8.</p> <p>I can now save curly quotes, curly apostrophoes, the £ symbols and dashes and all is fine. They load back into the CMS properly, and they format on the front end web pages correctly.</p> <p>However when I look at the data in the database. They are all mess up like:</p> <pre><code>&lt;p&gt;“I'm in double quotes man!â€&lt;/p&gt; </code></pre> <p>Is that to be expected - or should they look ok in the DB too? If so where am I going wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload