• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
£ sign getting messed - encoding problem

#1
[eluser]Xarren[/eluser]
Hey, Im currently having a problem submitting pound signs to my database. My database collation is UTF-8, and so is my "Content-Type text/html; charset=utf-8".
Yet whenever I submitted a £ sign I would end up with a ? mark sign. I realised I needed to encode my data.
Having done so however, created an all new problem. All other characters seem fine now (as far as I have tested), however the £ sign is now entered into the database as "£". Im really confused by this, as as far as I am aware all my processing is done using UTF-8, and my pages are served up in UTF-8, so I can't see why that problem would occur.

Any ideas on how to fix this?

My model:
Code:
function update_girl($id)
    {
        $data = array();
        $inputs = $this->config->item('girl_data_inputs');
        foreach ($inputs as $input)
        {
            $data[$input] = $this->input->post($input);
            if(!empty($data[$input]))
            {
                $data[$input] = mb_convert_encoding($data[$input], 'UTF-8');
                $data[$input] = htmlentities($data[$input],ENT_QUOTES,'UTF-8');
            }
        }
        
        $this->db->where('id', $id);
        $this->db->update($this->table, $data);
    }

PS: I've also tried
Code:
$decoded = str_replace('Â','',$decoded);
however that doesnt seem to work for me neither. (used it within the decode() method.

#2
[eluser]InsiteFX[/eluser]
Run PHPMyAdmin then click on your database then operations tab
and see what your database collation is!

Should be set to utf8_unicode_ci

InsiteFX

#3
[eluser]Xarren[/eluser]
I had it on UTF-8_bin, changed it to unicode_ci, while at it changed the table collation + field collations (stupidly I went through every field, before realising that I only need to do one to test if it works, joy Smile) - That was no good still doing exactly the same thing.

Thats my header loaded before each file, just putting it here to confirm that my header-content command is correct.. It displays just fine when I look at the response in FireBug:
Code:
<?php header('Content-type: text/html; charset=utf-8'); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;DD Admin&lt;/title&gt;
    [removed][removed]
    [removed]
        var baseurl = "&lt;?php echo base_url(); ?&gt;";
    [removed]
    [removed][removed]
    &lt;link rel="stylesheet" href="/css/admin_style.css" type="text/css"/&gt;
&lt;/head&gt;
&lt;body&gt;
    <div id="message"/>
    </div>

How frustrating, never had this problem before, I assume that the only explanation is a misconfigured database, but I've spent the whole day staring at my config, going through each bit trying to work out at which stage the encoding is messed up.

Are there any tools to view POST data, so that I can have a look whether my form is posting the correct value?

Got to love when stuff like this happens on a project which was meant to be ready yesterday Smile.

#4
[eluser]InsiteFX[/eluser]
Code:
&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /&gt;
&lt;/head&gt;

Try that

InsiteFX

#5
[eluser]Xarren[/eluser]
That didnt help Sad

Here are my mysql variables. I have no clue where to change the ones which are not on UTF, nor what "Global" means, could you advise me please if any of this may be causing the problem?

Code:
character set client      utf8
(Global value)     latin1
character set connection     utf8
(Global value)     latin1
character set database     latin1
character set filesystem     binary
character set results     utf8
(Global value)     latin1
character set server     latin1
character set system     utf8
character sets dir     /usr/share/mysql/charsets/
collation connection     utf8_unicode_ci
(Global value)     latin1_swedish_ci
collation database     latin1_swedish_ci
collation server     latin1_swedish_ci

#6
[eluser]eokorie[/eluser]
Can't you not just use
Code:
&pound;
instead of the typical £?

#7
[eluser]Xarren[/eluser]
Sorry.. Cant I use what instead of the typical £?

#8
[eluser]eokorie[/eluser]
Code:
&pound;

#9
[eluser]InsiteFX[/eluser]
You need to change the database collation it is set to latin1

PHPMyAdmin
Select your database
then click on the right top tab operations
on that screen at the bottom you will see your database collation
change it to utf8_unicode_ci

When you create any new database MySQL defaults to a collation of latin1_swedish_ci

InsiteFX

#10
[eluser]Xarren[/eluser]
Ahh, no I can't - Its for the content management system, telling all the users to suddenly start using &pound; wouldn't go down too well, that would just be taking the piss out of my employee really, giving him a website and telling him "Oh btw this and this doesnt work here, you ll need to tell all your members that, do you want me to make a big bright alert box telling your members that your website doesnt work? Smile"


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.