Jump to content
Larry Ullman's Book Forums

Best Mysql Character Set And Collation


Recommended Posts

Does UTF-8 cover the characters that could be used in a name from, say, China or Norway?

 

Yes, it would. I'm Norwegian myself, and it works perfectly.

 

- Use utf8_general_ci as collation

- Set PHPs MySQL(i)s charset by using mysqli_set_charset($connection, "utf8");

- Save files at UTF-8.

 

These three steps will ensure transfered data to the database is UTF8.

 

Else, you might experience weird charachters in the DB. This issue if often solved by utf_encode($variable), but you should not have to do this. :)

  • Upvote 1
Link to comment
Share on other sites

If you use UTF-8 in your database and in your php files, you should also have a look at the multibyte functions. For instance, if you want to make a string uppercase, you shouldn't use the strtoupper function, but the mb_strtoupper function instead. Test this, and you'll see why!

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Set locale</title>
<link rel="stylesheet" href="includes/styles_tests.css" type="text/css" media="all" />
</head>
<body>

<?php
$str = 'J\'ai reçu de très bons échos à la sortie.';
$str = strtoupper($str);
echo '<h3>Using strtoupper</h3>
<p><code>'.$str.'</code></p>';

date_default_timezone_set('Europe/Paris');
setlocale(LC_ALL, 'fr_FR.UTF-8');
$str = 'J\'ai reçu de très bons échos à la sortie.';
$str = mb_strtoupper($str, "utf-8");
echo '<h3>Using mb_strtoupper</h3>
<p><code>'.$str.'</code></p>';
?>
</body>
</html>

 

I hope this helps,

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...