Show different charset in UTF8 content

General project discussion. NOT for help questions.
Post Reply
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am

Show different charset in UTF8 content

Post 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
gertvdijk
Forum Members
Forum Members
Posts: 13
Joined: Tue Aug 28, 2007 2:58 pm

Re: Show different charset in UTF8 content

Post 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");
Last edited by gertvdijk on Wed Aug 29, 2007 10:28 pm, edited 1 time in total.
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am

Re: Show different charset in UTF8 content

Post by xmas3 »

Thanks a lot, but where should I put it into my code?
Sorry, I am still php newbie...
gertvdijk
Forum Members
Forum Members
Posts: 13
Joined: Tue Aug 28, 2007 2:58 pm

Re: Show different charset in UTF8 content

Post 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.
Last edited by gertvdijk on Wed Aug 29, 2007 10:29 pm, edited 1 time in total.
xmas3
Forum Members
Forum Members
Posts: 41
Joined: Sat Jul 28, 2007 9:22 am

Re: Show different charset in UTF8 content

Post 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
gertvdijk
Forum Members
Forum Members
Posts: 13
Joined: Tue Aug 28, 2007 2:58 pm

Re: Show different charset in UTF8 content

Post 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)
cyberman

Re: Show different charset in UTF8 content

Post 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 :).
Post Reply

Return to “General Discussion”