Author Topic: Problem with my encoding ! How to resolve ?  (Read 10148 times)

0 Members and 1 Guest are viewing this topic.

Offline ersinhakera

  • Pre-Newbie
  • Posts: 4
    • View Profile
Problem with my encoding ! How to resolve ?
« on: January 08, 2009, 03:30:05 PM »
I have got a problem with my encoding on site, because i`m writing on Bulgarian (cyrilic). To resolve problem, i`m asked in bulgarian forum for my problem. They answered me, giving the following code :
Code: [Select]
mysql_query("SET CHARACTER SET cp1251");
mysql_query("SET NAMES cp1251");
and say me to put them in config.php . If anybody make this for me :( I`don`t know in who files, and where in the files to put them.  :cry:

This must be put before <?php : 
Code: [Select]
<meta http-equiv="content-type" content="text/html; charset=windows-1251">These codes after
Code: [Select]
<?php:  iconv_set_encoding("internal_encoding""windows-1251"); 
iconv_set_encoding("output_encoding""windows-1251"); 
iconv_set_encoding("input_encoding""windows-1251"); 
iconv_set_encoding("all""windows-1251");
And after every query they say me to put this code :
Code: [Select]
mysql_query("SET CHARACTER SET cp1251");
Pls help me with examples, or directly with ready files  :cry:

« Last Edit: January 08, 2009, 03:40:52 PM by ersinhakera »

Offline ersinhakera

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Problem with my encoding ! How to resolve ?
« Reply #1 on: January 09, 2009, 02:03:59 PM »
Nobody knows?  :cry: :cry: :cry:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Problem with my encoding ! How to resolve ?
« Reply #2 on: January 09, 2009, 03:39:34 PM »
Let's start from the beginning. Please tell us what 4images version do you use and what kind of problem you have.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Anya

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Problem with my encoding ! How to resolve ?
« Reply #3 on: January 22, 2009, 12:31:32 PM »
I have the same problem, all russian words are displayed like this ���. (Version 1.7.6 )
everything worked fine when I tested the gallery on my local server (Windows OS), but now it is installed on another server (which is not Windows one and the encoding is not windows-1251 by default). I think I need to paste some code into the .php file related to the database, but i'm not sure.
Can you help me?

Thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Problem with my encoding ! How to resolve ?
« Reply #4 on: January 22, 2009, 03:39:34 PM »
Try add into .htaccess:

Code: [Select]
AddDefaultCharset windows-1251
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline alekinna

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Gallery of cross-stitching
Re: Problem with my encoding ! How to resolve ?
« Reply #5 on: January 22, 2009, 04:28:58 PM »
Before installation open the file data/database/default/mysql_default.sql
and replace each
Code: [Select]
TYPE=MyISAM;
with
Code: [Select]
TYPE=MyISAM CHARACTER SET=cp1251;
change cp1251 to encoding of your site


2. in the file includes/db_mysql.php

find
Code: [Select]
function Db($db_host, $db_user, $db_password = "", $db_name = "", $db_pconnect = 0) {
    $connect_handle = ($db_pconnect) ? "mysql_pconnect" : "mysql_connect";
    if (!$this->connection = $connect_handle($db_host, $db_user, $db_password)) {
      $this->error("Could not connect to the database server ($db_host, $db_user).", 1);
    }
    if ($db_name != "") {
      if (!@mysql_select_db($db_name)) {
        @mysql_close($this->connection);
        $this->error("Could not select database ($db_name).", 1);
      }
    }
    return $this->connection;
  }

replace with
Code: [Select]
function Db($db_host, $db_user, $db_password = "", $db_name = "", $db_pconnect = 0) {
    $connect_handle = ($db_pconnect) ? "mysql_pconnect" : "mysql_connect";
    if (!$this->connection = $connect_handle($db_host, $db_user, $db_password)) {
      $this->error("Could not connect to the database server ($db_host, $db_user).", 1);
    }
mysql_query ("set character_set_client='cp1251'");
mysql_query ("set character_set_results='cp1251'");
mysql_query ("set collation_connection='cp1251_general_ci'");
    if ($db_name != "") {
      if (!@mysql_select_db($db_name)) {
        @mysql_close($this->connection);
        $this->error("Could not select database ($db_name).", 1);
      }
    }
    return $this->connection;
  }

change cp1251 to encoding of your site


3. if you use cp1251 - in the file includes/search_utils.php

find
Code: [Select]
$val = convert_special($val);
replace with
Code: [Select]
// $val = convert_special($val);
3.a if you use utf8 -  in the file includes/search_utils.php

find
Code: [Select]
function convert_special($text) {
  return strtr(
    $text,
    array(
      "Ä" => "AE",
      "Ö" => "OE",
      "Ü" => "UE",
      "ä" => "ae",
      "ö" => "oe",
      "ü" => "ue",
      "ß" => "ss"
    )
  );
}

replace with
Code: [Select]
function convert_special($text) {
  return strtr(
    $text,
    array(
      "×" => "÷",
      "Á" => "á",
      "¨" => "Å",
      "¸" => "å"
    )
  );
}

and save the file in utf-8 format

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Problem with my encoding ! How to resolve ?
« Reply #6 on: January 22, 2009, 04:36:46 PM »
If I'm not mistaken, 4images doesn't care about mysql charset, it encodes any non-latin letters into HTML entities codes, which makes the text charset independent.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Anya

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Problem with my encoding ! How to resolve ?
« Reply #7 on: January 22, 2009, 08:17:30 PM »
Try add into .htaccess:

Code: [Select]
AddDefaultCharset windows-1251

Thanks, everything works fine now :)

Offline Anya

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Problem with my encoding ! How to resolve ?
« Reply #8 on: January 22, 2009, 09:26:37 PM »
Now when I try to add a category/image description in russian, or change the category/image name to russian - it looks like this: ??????????
but the language pack works properly, all the fields are displayed in russian correctly...

Offline V@nо

  • Addicted member
  • ******
  • Posts: 1.223
    • View Profile
Re: Problem with my encoding ! How to resolve ?
« Reply #9 on: January 22, 2009, 09:40:40 PM »
is that with unmodified 4images?
Your first three "must do" before you ask a question:
If I asked you to PM me, I meant PM to my primary account, this account doesn't accept PMs.

Offline Anya

  • Newbie
  • *
  • Posts: 24
    • View Profile
Re: Problem with my encoding ! How to resolve ?
« Reply #10 on: January 22, 2009, 11:13:07 PM »
sorry, I forget to replace the file includes/db_mysql.php with unmodified one after trying to fix the previous problem with encoding. Everythink is ok  :D Thanks for help thou  :D

Offline 790511

  • Pre-Newbie
  • Posts: 4
    • View Profile
Where to put this lines?
« Reply #11 on: July 25, 2011, 10:42:43 PM »
Hi, I have a similar problem. After I have moved my web to new hosting and import saved database, some Czech characters are shown incorrectly in the webpage, although they are OK in phpMyAdmin. This problem is reported many times and the most frequent solution seems to be to put:

mysql_query
("SET CHARACTER SET cp1250"); 
mysql_query("SET NAMES cp1250");

This is supposed to be between
mysql_connect(...);
...
mysql_select_db(...);

My question is: where could I place this piece of code in my good old 4images 1.7.4? For me it is quite hard to find it as the code is quite complicated. Thanks in advance for your kind help.