ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

issues with UTF8 and ANSI

November 02, 2011 1:35pm

Subscribe [1]
  • #1 / Nov 02, 2011 1:35pm

    Valhallen

    10 posts

    I’m a bit dumb when it comes to encodings. So please, bear with me.

    When creating my own content, be it libraries, configs, models, controllers etc, I always encode them in utf8 without bom. I have a live site running PHP5.3.3 (CGI), Apache 2.2.13, Unix with Codeigniter 2.0.2 and Smarty 3.0.8. It works just fine.

    But recently I started developing it again and at first I used CI 2.0.2 but moved to 2.0.3 and now on to the latest github version.

    So, the issue is that SOME of my utf8 files are creating whitespace and that screws up the outputted HTML. I did the following tests:

    First test
    1. downloaded latest CI from github
    2. created a small library

    <?php
    class Test
    {
     public function __construct()
     {
      
     }
    }

    3. saved the file as utf8 w/o bom
    4. added it to autoload.php

    all good, so far. no whitespace yet.


    Second test
    1. I created an additional library called Smarty_wrapper with this code:

    <?php
    require_once APPPATH.'third_party/smarty/Smarty.class.php';
    class Smarty_wrapper extends Smarty
    {
     public function __construct()
     {
      parent::__construct();
     }
    }

    2. saved it as utf8. this created whitespace.
    3. saved it as ansi. this fixed the whitespace issue.


    Third test
    1. saved test.php as ansi. now both the test and smarty wrapper are ansi. all good. works fine.
    2. saved smarty wrapper to utf8. now test is ansi and smarty_wrapper is utf8 (this encoding previously created whitespace with given file). works great. no whitespace.

    so these tests show that both libraries can’t be simultaneously encoded in utf8.

    what’s going on here? should I convert all my files to ansi? and why hasn’t this issue occured with the live version?

  • #2 / Nov 02, 2011 1:40pm

    Valhallen

    10 posts

    also, the whitespace’d code looks like this:

    <!-- saved from url=(0025)http://localhost/citest2/ -->
    <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>
    
    
    
     <meta charset="utf-8">
     <title>Welcome to CodeIgniter</title>
    
     <style type="text/css">
    
     ::selection{ background-color: #E13300; color: white; }
     ::moz-selection{ background-color: #E13300; color: white; }
     ::webkit-selection{ background-color: #E13300; color: white; }
    
     body {
      background-color: #fff;
      margin: 40px;
      font: 13px/20px normal Helvetica, Arial, sans-serif;
      color: #4F5155;
     }
    
     a {
      color: #003399;
      background-color: transparent;
      font-weight: normal;
     }
    
     h1 {
      color: #444;
      background-color: transparent;
      border-bottom: 1px solid #D0D0D0;
      font-size: 19px;
      font-weight: normal;
      margin: 0 0 14px 0;
      padding: 14px 15px 10px 15px;
     }
    
     code {
      font-family: Consolas, Monaco, Courier New, Courier, monospace;
      font-size: 12px;
      background-color: #f9f9f9;
      border: 1px solid #D0D0D0;
      color: #002166;
      display: block;
      margin: 14px 0 14px 0;
      padding: 12px 10px 12px 10px;
     }
    
     #body{
      margin: 0 15px 0 15px;
     }
     
     p.footer{
      text-align: right;
      font-size: 11px;
      border-top: 1px solid #D0D0D0;
      line-height: 32px;
      padding: 0 10px 0 10px;
      margin: 20px 0 0 0;
     }
     
     #container{
      margin: 10px;
      border: 1px solid #D0D0D0;
      -webkit-box-shadow: 0 0 8px #D0D0D0;
     }
     </style>
    
    
    
    <div id="container">
     <h1>Welcome to CodeIgniter!</h1>
    
     <div id="body">
      The page you are looking at is being generated dynamically by CodeIgniter.
    
      If you would like to edit this page you'll find it located at:
      <code>application/views/welcome_message.php
    The corresponding controller for this page is found at: application/controllers/welcome.php If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide. </div> Page rendered in 0.0515 seconds. CodeIgniter Version 3.0-dev </div> </body></html></code>

    notice how the title tag has moved in the body. this was saved with Chrome. the actual view source of the generated page shows correct markup. but when saving the file or viewing it with development tools, it returns this incorrect markup

  • #3 / Nov 03, 2011 7:56am

    Valhallen

    10 posts

    fixed. it was a case of some included files having BOM

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases