Jump to content

utf-8 encoding problems


azazel141

Recommended Posts

I have this in head:

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

 

This in body:

 

    <select name="land" size="1" onchange="showRegio(this.value)">

    <option value="default">Kies een land..</option>

    <?php

$query = "SELECT name, landid FROM land";

$sql = mysqli_query($mysqli, $query);

 

while($record = mysqli_fetch_object($sql))

{

echo '<option value="'.$record->landid.'">'. $record->name.'</option>';

}

?>

    </select>

 

But when look at the values inserted from the DB I see questionmarks where there should be an 'ë'.

ex: Belgi? and Argentin?. This should be->België and Argentinië.

 

A solution I found but I'm not happy with:

 

utf8-encode($record->name)

 

I have lots and lots more of these lists and labels and I don't think surrounding every value with utf8-encode() is the most efficient way of programming.

Link to comment
Share on other sites

Do you have access to your php.ini file? If so, check what the default encoding is. I'm guessing its probably ISO-8859-1. Or if you are getting this text from a database, the database probably isn't set to UTF-8. Check these two things first. Im thinking its probably the first one though.

Link to comment
Share on other sites

Leave the default charset as utf-8, thats important.

 

First a question: If you go to view -> character encoding  in your browser window, what is the setting?

 

Next: Is the text that is coming out as question marks dyamic (from the database) or hard coded into the document?

Link to comment
Share on other sites

Ok, lets double check to make sure you definitely have your charset set correctly in php. Create a new file, and add echo phpinfo()  into the file (sorry I cant put this in code tags, it screws up this site)

 

Then upload that file to your server and run it. Look under php core, and make sure it says utf-8 under the default charset. I'll let you know what to try after that.

Link to comment
Share on other sites

I read the site effigy proposed and I solved the problem by executing a SET NAMES utf8; query right after making a connection to the database.

 

Thank you all for the help. This was my first experience with phpfreaks and I am astonished by the quick and professional replies.

 

 

*now trying to find the topic solved button*

Link to comment
Share on other sites

The topic solved button is broken.

 

That was going to be my next suggestion, but I wanted to make sure that you had the correct encoding first.

 

Encoding is a hassle! I work in a Japanese company, so I have to do Japanese encoding for our sites. I've had more headaches from that than I can count!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.