Jump to content
Larry Ullman's Book Forums

Recommended Posts

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

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));

}

  • Upvote 1
Link to comment
Share on other sites

  • 1 year later...

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

 Share

×
×
  • Create New...