Page 1 of 1

ucfirst & mbstring

Posted: Sat Nov 27, 2004 2:46 am
by CapriSkye
the problem is caused by ucfirst and my misconfiguration of database...


i was just testing the blog to see how well it handles chinese characters, everything seems fine except when i'm using php with mysql extension, chinese characters have trouble showing up. when im creating a category with chinese character, it will not show the character, just blank. the category is created though, just unable to click it.
then after some uninstalling and installing of php and mysql, i found out it's cause by the extension, it works totally fine with mysqli but not mysql. i have a friend that's using this blog also, and i don't think he's using mysqli, so maybe there's something wrong with my server set up.
it'd be good to use mysql extension instead of mysqli though, since coppermine gallery doesn't support mysqli.
im totally newb when it comes to this, but maybe the developers have ideas about the differences?
thanks

Posted: Sun Nov 28, 2004 5:42 am
by Guest
after more messing around, it's probably not because of mysql and mysqli. i think it has something to do with the encoding. i've converted the language pack to utf-8 and choose mysql instead of mysqli, now everything seems okay. except some character won't show up, like showing here,

Image[/img]

Posted: Mon Nov 29, 2004 11:12 am
by garvinhicking
Yes, it more likely depends on your MySQL setup and how it handles the encodings. Can you use a tool like phpMyAdmin and browse the database (serendipity_categories) to see, if the characters got properly inserted?

If they didn't get inserted correctly, there may be a superfluous call to some PHP escaping functions - but I think we don't use such messing character functions...

Regards,
Garvin

Posted: Wed Dec 01, 2004 4:29 am
by CapriSkye
the category problem is gone, but the problem shown in the pic still exist.
Image

i've narrowed down the problem, it's probably my mysql encoding. it doesn't happen to one of my friend's blog, and he has mysql version 4.0 with s9y v0.7, and i'm using 4.1. i installed both 0.8alph3 version and 0.7 version, both have the same problem. and we both using utf-8 encoding for blog language. weird stuff...

Posted: Wed Dec 01, 2004 12:29 pm
by garvinhicking
Hm, to which character set and collation type did you set your s9y tables and the mysql connection? That's quite important in dealing with MySQL 4.1...

Regards,
Garvin.

Posted: Wed Dec 01, 2004 10:39 pm
by CapriSkye
for the ENTRIES string, the blog will mess up the first character in the string, so I put a space in front of it, then I'm able to make it showing the correct characters. i still wonder why this would happen though. My mysql encoding is utf-8, with utf-8 collation, and im using utf-8 language file.

Posted: Wed Dec 01, 2004 10:41 pm
by CapriSkye
ok i found another solution, in serendipity_entries.php,
i changed
<?php echo ucfirst(ENTRIES); ?>
to
<?php echo ENTRIES; ?>

what is ucfirst() for? thanks

Posted: Wed Dec 01, 2004 11:09 pm
by garvinhicking
Ah, now I know. UCFirst is used to uppercase the first letter, and it can't deal with UTF8 character. For that, one would need the 'mb_strtoupper' function. Thinking about it, there may be a lot of other places where we use strtolower/stroupper instead of the MBstring functions. Sadly, the mb-functions are only available if the PHP extension 'mbstring' is installed, and if that is missing, one can't deal with UTF8 characters propperly.

I'll look into how many functions are affected by this...

Regards,
Garvin

Posted: Thu Dec 02, 2004 3:13 pm
by garvinhicking
I just patched CVS to faciliate the use of 'mbstring'. You need to make sure that the module is compiled into your PHP.

If not, there is a 'ucfirst' stub left in the file include/lang.inc.php, which you could modify like this:

Code: Select all

        switch($func) {
            case 'ucfirst':
                // there's no mb_ucfirst, so emulate it
                if ($mbstring) {
                    return mb_strtoupper(mb_substr($args[1], 0, 1)) . mb_strtolower(mb_substr($args[1], 1));
                } else {
                    return ucfirst($args[1]);
                }
to:

Code: Select all

        switch($func) {
            case 'ucfirst':
                // there's no mb_ucfirst, so emulate it
                if ($mbstring) {
                    return mb_strtoupper(mb_substr($args[1], 0, 1)) . mb_strtolower(mb_substr($args[1], 1));
                } else {
                    return $args[1];
                }
(but first try to enable mbstring PHP module, that is the only real way to make it work properly)

Have fun with it, and please report if there are any "strange character" issues left! :)

Posted: Fri Dec 03, 2004 6:29 am
by CapriSkye
thank you very much for the time, i haven't updated to the latest cvs yet, but i will try later.
also if i enable mbstring.dll in php, do i do anything to [mbstring] section? thanks

Posted: Fri Dec 03, 2004 10:50 am
by garvinhicking
No, if you activated mbstring.dll in PHP you won'T have to change anything, then it should work out of the Box :-)

Regards,
Garvin