Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

UTF-8 Encoding (PHP + MYSQL)

Name: Anonymous 2006-03-08 13:25

Hi there.

My first attempt to handle UTF-8 with php and mysql has failed...

I currently build a small test website and wanted to do a "wakaba/4chan" style BBS and failed again ^_^

Anyway, the main goal is to be able to include some japanese in the pages/posts.

Right now including Japanese in the page is no problem, but when anon is posting on the BBS, PHP seems to send MYSQL some buggy string instead of the user-input.

example:
  /l、
(゚、 。 7
 l、 ~ヽ   
 じしf_, )ノ

will produce:
��l�
��、 。 �
�l� ~����
���f_, )�

o_O Mozilla tells me the page encoding IS UTF-8... Any idea?

http://rei.xephon.be/site/bbs/

Name: Anonymous 2006-03-08 14:22

Found the error ---> HTMLENTITIES($content)

Name: Anonymous 2006-03-08 16:08

UTF-8, php and mysql on the same line reads like a joke. Give up on proper internationalization with php.

Name: Anonymous 2006-03-08 17:49

1) The default version of Futallaby always worked fine for me with Unicode pages.  It sent crap to MySQL when using Japanese, but the crap magically worked on the way out.  The only time it got screwed up was restoring backups and whatnot.

2) Converting to handle Unicode properly took like 3 minutes.  This was years ago, but the most complex parts were adding this to the PHP:
    ini_set ( 'mbstring.internal_encoding', 'UTF-8' );
    ini_set ( 'mbstring.script_encoding', 'UTF-8' );
    ini_set ( 'mbstring.func_overload', '7' );
And making sure the MySQL tables/fields had their character sets set to Unicode.  You need MySQL 4.1 or later for this and the mbstring extension for PHP (http://us2.php.net/mbstring).

Name: Anonymous 2006-03-08 22:07

Seems like the Error was on the Mysql Side.
Had to change the data format to UTF8_general_ci and tells mysql the string wich will be received is UTF8

header("Content-Type: text/html; Charset=utf-8");
mysql_query("SET NAMES 'utf8'");

As for the Script showing threads:
$content = htmlentities(stripslashes($post->content),ENT_COMPAT,'UTF-8');

kinda solved the problem

Name: Anonymous 2006-03-09 4:32

You can set the encoding of a DB when you create it, or change it afterwards (with wonderfugly results), I think.

Name: Anonymous 2006-03-09 19:27 (sage)

Yes you can change the Encoding of the DB
The problem is the Mysql Client php is using. Mysql not expect utf-8 encoding for the data transmission even if the database is in utf-8. To fix the behavior you msut tell MYSQL the upcoming data will be UTF-8: mysql_query("SET NAMES 'utf8'");

With php, some string functions will not work properly without some options. htmlentities being one of them. You must use htmlentities([utf-8 string to parse],ENT_COMPAT,'UTF-8')
in order to make it work as it should (otherwise it will screw up your utf-8 encoding).

Name: Anonymous 2009-08-17 0:05

Lain.

Name: Anonymous 2011-10-03 3:08

I don't give a flying fuck about this thread... I just wanted to let people know that if you mix 180 proof vodka and Bacardi Mojito... you are in for a hell of a night.

Don't change these.
Name: Email:
Entire Thread Thread List