Hope4You Posted December 17, 2011 Share Posted December 17, 2011 My database character set is currently UTF-8. What would happen if I tried to INSERT a non-UTF8 character? Would it save properly? Does UTF-8 cover the characters that could be used in a name from, say, China or Norway? Thanks again. Link to comment Share on other sites More sharing options...
Larry Posted December 19, 2011 Share Posted December 19, 2011 I don't know that it's possible to insert a non-UTF8 character, which is to say that I'm not sure there are any characters that don't fall under UTF-8. Certainly all known languages are covered. Link to comment Share on other sites More sharing options...
Antonio Conte Posted December 24, 2011 Share Posted December 24, 2011 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. 1 Link to comment Share on other sites More sharing options...
Josee Posted December 27, 2011 Share Posted December 27, 2011 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, 1 Link to comment Share on other sites More sharing options...
Antonio Conte Posted December 27, 2011 Share Posted December 27, 2011 Great tip, Josee. You should always use the mb functions (Multibyte String Functions) if they need to work with Unicode characters. Link to comment Share on other sites More sharing options...
Recommended Posts