We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21365
    • 10 Posts
    I have a problem that seems related to character sets, although I can’t figure out exactly how.

    I’m pulling data from a UTF-8 database (modx is also set to utf8) on the same server as the modx database. When I pull and display the data through a modx page, all smart quotes are displayed as unknown characters (�). If I view the source text, however, all of the characters are present and displaying correctly.

    If I enter smart quotes directly into a modx page via the text editor, they display correctly. If I make the database call from a straight PHP page (not parsed through modx) they also display correctly, albeit only if I specify ’latin1’ or ’utf8_unicode_ci’ as the collation. (Using the utf8 collation returns unknown characters for smart quotes. )

    I’m using MySQL version 5.1.30 (charset utf8, connection collation: utf8_unicode_ci) and Modx version 0.9.6.2. Modx manager shows the modx charset as utf8 and seems to have no option for switching to latin1 (although latin3 is present). I’ve tried modifying manager/includes/config.inc.php to use latin1 and SET NAMES for the database connection, but that seems to have no effect.


      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: nfulda at May 15, 2009, 04:59 AM

      I have a problem that seems related to character sets, although I can’t figure out exactly how.

      I’m pulling data from a UTF-8 database (modx is also set to utf8) on the same server as the modx database. When I pull and display the data through a modx page, all smart quotes are displayed as unknown characters (�). If I view the source text, however, all of the characters are present and displaying correctly.

      If I enter smart quotes directly into a modx page via the text editor, they display correctly. If I make the database call from a straight PHP page (not parsed through modx) they also display correctly, albeit only if I specify ’latin1’ or ’utf8_unicode_ci’ as the collation. (Using the utf8 collation returns unknown characters for smart quotes. )

      I’m using MySQL version 5.1.30 (charset utf8, connection collation: utf8_unicode_ci) and Modx version 0.9.6.2. Modx manager shows the modx charset as utf8 and seems to have no option for switching to latin1 (although latin3 is present). I’ve tried modifying manager/includes/config.inc.php to use latin1 and SET NAMES for the database connection, but that seems to have no effect.
      If by smart quotes you mean Windows extended ASCII characters, these are not valid utf8 characters and will not translate properly from MySQL. If you use utf8 and set names, you should be fine, but you’ll need to replace all those invalid characters. Otherwise, you need to start with a clean database in latin1 and use latin1 all the way around so you can have your extended ASCII characters.
        • 21365
        • 10 Posts
        Yes, I’m referring to extended ASCII characters.

        these are not valid utf8 characters and will not translate properly from MySQL. If you use utf8 and set names, you should be fine, but you’ll need to replace all those invalid characters.

        Let me make sure I’ve understood correctly: You’re saying that if I use utf8 and set names, the characters will come through the connection, but will need to be converted before they’ll display correctly? Are you referring to a character-by-character conversion in PHP?

        Also, if the non-utf8 characters will not translate properly from MySQL, why do they display correctly when I view the source code from my browser?
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: nfulda at May 15, 2009, 12:43 PM

          Yes, I’m referring to extended ASCII characters.

          these are not valid utf8 characters and will not translate properly from MySQL. If you use utf8 and set names, you should be fine, but you’ll need to replace all those invalid characters.

          Let me make sure I’ve understood correctly: You’re saying that if I use utf8 and set names, the characters will come through the connection, but will need to be converted before they’ll display correctly? Are you referring to a character-by-character conversion in PHP?

          Also, if the non-utf8 characters will not translate properly from MySQL, why do they display correctly when I view the source code from my browser?
          You said your database was utf8; you simply cannot store those characters in a utf8 database and pull them out properly. Your database needs to be latin1 and you front-end needs to use ISO-8859-1 to display those characters properly. Also, it’s not just the database, but the individual table columns’ collations settings that matter, and if those don’t match your database, you are going to further confuse the real issue. Without actually seeing all of your database, php, and modx settings, it’s very difficult to diagnose these problems accurately.

          I don’t know what you mean by source code from browser. Using what application?
            • 21365
            • 10 Posts
            I don’t know what you mean by source code from browser. Using what application?

            I’m using Internet Explorer, and when I click on View/Source in my browser menu, the html document that’s pulled up (in Notepad) displays the smart quotes correctly.

            This is why I’m confused when you say the utf8 database can’t store those characters, because they clearly are being retrieved, even though the browser isn’t displaying them properly. Perhaps PHPMyAdmin is not displaying the actual database collations correctly?

            Thank you very much for spending time to discuss this with me, by the way. I think Modx is a fantastic CMS and I appreciate all the work that goes into developing and supporting it.
              • 21365
              • 10 Posts
              Just wanted to let you know I’ve resolved this issue by setting the modx charset to iso-8859-1 in the configuration menu and by setting config.inc.php to use

              $database_connection_charset = ’’;
              $database_connection_method = ’SET NAMES’;


              Thank you again, Jason, for taking time to provide extra information. It turned out to be very helpful.

              Best,
              Nancy