ucfirst & mbstring

Found a bug? Tell us!!
Post Reply
CapriSkye
Regular
Posts: 119
Joined: Sun Oct 31, 2004 4:42 am
Location: Taiwan
Contact:

ucfirst & mbstring

Post 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
Last edited by CapriSkye on Sun Dec 12, 2004 2:35 am, edited 1 time in total.
Guest

Post 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]
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
CapriSkye
Regular
Posts: 119
Joined: Sun Oct 31, 2004 4:42 am
Location: Taiwan
Contact:

Post 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...
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
CapriSkye
Regular
Posts: 119
Joined: Sun Oct 31, 2004 4:42 am
Location: Taiwan
Contact:

Post 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.
CapriSkye
Regular
Posts: 119
Joined: Sun Oct 31, 2004 4:42 am
Location: Taiwan
Contact:

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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! :)
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
CapriSkye
Regular
Posts: 119
Joined: Sun Oct 31, 2004 4:42 am
Location: Taiwan
Contact:

Post 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
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post 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
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply