Page 1 of 1

Show different charset in UTF8 content

Posted: Wed Aug 29, 2007 8:55 pm
by xmas3
Hello,
I have this problem.
I am trying to display the content of DB in cp1250 on my page, which is in UTF8 and another mySQL database.
I have created my own UDT called php_projekty which is connecting the DB and then echo-ing the result.
------------
mysql_connect('server_name','login','password');
        mysql_select_db('test');
     
$dnes = date("Y-m-d"); 
$query = "SELECT nazov, cislo, zaciatok, koniec, riesitel, popis, id, radenie FROM projekty where radenie>='$dnes' ORDER BY radenie ASC" ;  // Standard query.
$result = mysql_query ($query);
        $pocet = mysql_num_rows($result);
       
{echo 'Rozpracované projekty (', $pocet, ')
';}
while ($row = mysql_fetch_array($result, MYSQL_NUM))

{echo '
    ', $row[0], '
Projekt č:', $row[1], '

Začiatok riešenia:', $row[2], '

Koniec riešenia: ', $row[3], ', projekt je v realizácii

Zodpovedný riešiteľ:', $row[4], '

>>> viac o projekte



-------------
and the in the content page inserted
{php_projekty}

The problem is, that the special /local/ characters are not showing well and I become lot of ? and so on.
Is it possible to store the table in cp1250 and convert it somehow to utf8?
Thanks a lot
Miro

Re: Show different charset in UTF8 content

Posted: Wed Aug 29, 2007 9:47 pm
by gertvdijk
xmas3 wrote: The problem is, that the special /local/ characters are not showing well and I become lot of ? and so on.
Is it possible to store the table in cp1250 and convert it somehow to utf8?
By using this php function: mb_convert_encoding($string, "your-target-encoding", "your-source-encoding");

Re: Show different charset in UTF8 content

Posted: Wed Aug 29, 2007 10:13 pm
by xmas3
Thanks a lot, but where should I put it into my code?
Sorry, I am still php newbie...

Re: Show different charset in UTF8 content

Posted: Wed Aug 29, 2007 10:27 pm
by gertvdijk
xmas3 wrote: Thanks a lot, but where should I put it into my code?
You should replace every string that you want to be converted with the code I gave you.
So in your case, that would involve all row[number] strings. But your code is quite a mess, actually.
Put this in the while loop, before the echo statement:

Code: Select all

for ($i = 0; $i < 6; $i++){
$row[i] = mb_convert_encoding($row[i], "utf-8", "cp1250");
}
Now every $row[0] ... $row[5] is converted to UTF-8, provided you define the right source encoding of the string. This could be 'windows-1250' or 'cp1250' or 'cp-1250'. Check that.
xmas3 wrote: Sorry, I am still php newbie...
Lol.

Re: Show different charset in UTF8 content

Posted: Wed Aug 29, 2007 10:40 pm
by xmas3
Thanks, I ve tryied it but it doesnt work.
I get Fatal error: Call to undefined function: mb_convert_encoding()
and the same with iconv() function.
Is it possible that the functions are not activated by the provider?
Miro

Re: Show different charset in UTF8 content

Posted: Wed Aug 29, 2007 10:49 pm
by gertvdijk
Yup, that's possible:
mbstring is a non-default extension. This means it is not enabled by default.
(source)

Although, mbstring (multibyte string functions extention for php) is default in my installation, afaik. (Debian etch, apach2-mod-php5)

Re: Show different charset in UTF8 content

Posted: Thu Aug 30, 2007 5:37 am
by cyberman
xmas3 wrote: Is it possible that the functions are not activated by the provider?
You can make a look with a phpinfo().

If it's not activated try to ask your provider. If he cant/wount help you have a reason to move your website :).