Skip to content Skip to sidebar Skip to footer

Incorrect Encoding From Php?

1) I have a table tbl_Data in database which has name column with text comparision method (?) property set toutf8_polish_ci. Works as a charm, when I'm browsing tbl_Data through ph

Solution 1:

so seems like I'm sending proper encoding headers for browser.

Wrong. <meta> is not an HTTP header but HTML tag, a non-standard one. So, your code still lacks proper header.

header('Content-Type: text/html; charset=utf-8');

My PDO dsn contains ;charset=UTF-8, followed from php manual.

if your PHP version is less than 5.3.6 it won't work either. use SET NAMES utf8 regular query instead

Solution 2:

There is no reason to use utf8_encode() if your text is already UTF-8 encoded.

A potential issue might be your version of PHP. The ;charset=UTF-8 element of your DSN is only supported by PHP version >= 5.3.6. Prior to 5.3.6 this element was silently ignored (instead of issuing a warning). More information and a workaround for this are available in the docs: http://php.net/manual/en/ref.pdo-mysql.connection.php

Solution 3:

Charset UTF-8 is good (in your html) :P

Try this.. (use new, experimental table for this, to check it out because I have no idea if your PHP script is cleaning $_POST entries for example, or doing something at all..)

  1. create column set to utf8_bin (not utf_ci_polish) named "polish_title"

  2. Before PHP passes (text input, polish) data to mysql INSERT (or update) covert those with this (PHP integrated) function

    $polish_input = htmlspecialchars($input_polish_data);

    INSERT INTO table_name (polish_title) values ('$polish_input');

You will see strange data in mysql table (via phpmyadmin) when polish signs are part of your input what is normal (or blobed), but good ones (polish native) on your site when you get mysql data out ;)

If this gonna work, ALL your mqsql (text) columns should be changed to utf8_bin. And to easy entries on yourself, you can create function which can "clean" all $_POST inputs on your website before those inputs engage to mysql DB.

Big plus on this is that visitors from other countries will see your native letters & signs (what is also important).

Edit (thx to Common Sense user input)

ANd yeah include this as a MUST also in your header

header('Content-Type: text/html; charset=utf-8');

Solution 4:

I could not comment on your post.....so I suggest here~_~ From here, it said utf8_encode — Encodes an ISO-8859-1 string to UTF-8 therefore, my question is: is your output is ISO-8859-1? may be you could create a normal English test record and try again.

Solution 5:

In your HTML code, try:

<metahttp-equiv="content-type"content="text/html; charset=utf-8">

Post a Comment for "Incorrect Encoding From Php?"