Solved

Set locale

Posted on 2010-11-16
3
385 Views
Last Modified: 2012-05-10
I have a script that extracts data from a mysql database. I works great until I extract a text that contains danish characters like æ, ø and å.

The output looks like this:
Tilmeld dig vores nyhedsbrev og v¿r med i konkurrencen om et gavekort p¿ 25.000 kr til dit favorit indk¿bscenter!

but it should look like this:
Tilmeld dig vores nyhedsbrev og vær med i konkurrencen om et gavekort på 25.000 kr til dit favorit indkøbscenter!

The script is this one:
 
<?php
$link = mysql_connect('mysql.myserver.dk:3306', 'username', 'password');
if (!$link) {
    die('could not connect: ' . mysql_error());
}
mysql_select_db('database_bk', $link);

$my_date=date('c');
$query="select * FROM `content_type_konkurrence` WHERE '$my_date' BETWEEN `field_konk_start_value` AND `field_konk_slut_value`";
$result=mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_assoc($result)) {

    echo "
<a class='konk_link' href='" . $row['field_konk_url_value'] . "'><div class='konk_div'>
<img src='http://www.mydomain.dk/files/" . $row['field_konk_billede_value'] . "' alt='" . $row['field_konk_titel_value'] . "' class='konk_billede' />
<span class='konk_tekst'><b class='konk_titel'>" . $row['field_konk_titel_value'] . "</b><br /><br />" . $row['field_konk_tekst_value'] . "</span></div></a><br />";
	
}

mysql_close($link);
?>

Open in new window


What must I do to replace those anoying ¿ with the danish characters.

Best regards
Kasper K
0
Comment
Question by:Kasper Katzmann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
Mestika earned 500 total points
ID: 34144648
Hi Kasper,

I am myself danish so I have dealt with this problem numerous times before. There are a lot of good articles which takes care of this subject but here are some key points.

You need to both specify your Database and your PHP code.

One thing you can start to try is to set your database to use utf8, in your php - database code:
mysql_set_charset('utf8');

like this:

mysql_set_charset('utf8');
$query="select * FROM `content_type_konkurrence` WHERE '$my_date' BETWEEN `field_konk_start_value` AND `field_konk_slut_value`";
$result=mysql_query($query) or die(mysql_error())

More, you can set the default charset in your database (assuming you use MySQL) to utf8 in your my.ini file.
0
 

Author Closing Comment

by:Kasper Katzmann
ID: 34144674
Ohh my god...

Was it that easy. I have tried with setlocale, but that didn't work at all. But you suggestion worked at once.

Thank you very much.
Jeg gi'r en øl (I buy you a beer)
0
 
LVL 3

Expert Comment

by:Mestika
ID: 34144735
Yeah it is that easy, but trust me, I created a whole method to begin with to work around the problem until I discovered how little it took to make it work.

I'm looking forward to the beer :-)
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question