brown.jeff Posted December 6, 2012 Share Posted December 6, 2012 I am working through the example-message board in chapter 17. I am having a problem displaying foreign language fonts on my web browser. For example, the Chinese characters are all questions marks when I view the message board in FireFox. However, when I view the form submissions in PhpMyAdmin, the Chinese/Japenese characters display properly. All of the files were saved as UTF-8. Thanks. Link to comment Share on other sites More sharing options...
HartleySan Posted December 6, 2012 Share Posted December 6, 2012 You also need to add the meta charset tag within the head element and set the charset attribute to "UTF-8". The following provides the necessary markup: http://www.w3schools.com/html5/att_meta_charset.asp Link to comment Share on other sites More sharing options...
Antonio Conte Posted December 6, 2012 Share Posted December 6, 2012 Using an IDE? Could be from there. If you are, right click project, select "properties" (or similar) and find charset there. My IDE has used macRoman too many times... It could also be an mysql thing. Try mysql(i)::set_charset(). This is also a common problem. http://php.net/manual/en/mysqli.set-charset.php 2 Link to comment Share on other sites More sharing options...
brown.jeff Posted December 7, 2012 Author Share Posted December 7, 2012 Antonio, Thank you! I found this code on the PHP Manual link you provided and it fixed the problem. /* change character set to utf8 */ if (!mysqli_set_charset($dbc, "utf8")) { printf("Error loading character set utf8: %s\n", mysqli_error($dbc)); } else { printf("Current character set: %s\n", mysqli_character_set_name($dbc)); } 1 Link to comment Share on other sites More sharing options...
ericp Posted February 27, 2014 Share Posted February 27, 2014 I just had a problem with charset utf8 for my script 17.7.php I add this into my connection script (mysqli_connect.php) as per the book guilde mysqli_set_charset($dbc, 'utf8'); And my live server is shared linux with Godaddy.com. The storage engine i am using is MySIAM, and the collocation is 'utf8_general_ci' and the PHP Version is 5.3.24 The form is also coded to accept utf8 one more time like this: <form action="" method="post" accept-charset="utf-8"> And the header .html file is also the same as the book guilde which includes this: header ('Content-Type: text/html; charset=UTF-8'); When I validate the form, using htmlentities for the textarea field as $body = htmlentities($_POST['body']); When I enter my language, Vietnamese, i.e. đình, it is converted to something like Ä If I exclude the htmlentities function, it becomes normal. So, How can I validate it using the htmlentities function for other languages beside English, as htmlentities will protect the form from hacking or so? or should I use another function? Thank you Link to comment Share on other sites More sharing options...
HartleySan Posted February 27, 2014 Share Posted February 27, 2014 Use htmlspecialchars instead. Link to comment Share on other sites More sharing options...
Recommended Posts