WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've been looking through Wordpress' codes and they're mostly using PHP's regular string functions, like strlen, strpos, etc. Yet I know Wordpress supports utf8, so how does it do that?

Does it overload the regular string functions with multibyte string functions?

If so, is that a good idea in practice? If not, then how do they do it?

share|improve this question

migrated from stackoverflow.com Mar 25 '13 at 11:09

This question came from our site for professional and enthusiast programmers.

Wordpress is written in PHP. As far as I know, PHP doesn't support any character encoding (UTF-8, UTF-16, ...). It just assumes the text to be ASCII encoded.

The actual encoding and decoding is done by your browser. When you write a post, your browser sends the text you just entered as UTF-8 to the server. Wordpress just stores it in the database.

The encoding is specified in Wordpress' HTML code:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

This instructs the browser to use "UTF-8" for all text on the page. This includes the actual text on the page as well as all input fields.

So, Wordpress doesn't handle UTF-8 itself. It let's the browser handle it. (This is also means, if you'd specify a different encoding for the backend and the frontend pages, you'd get garbage text on the frontend.)

As a note: Unlike PHP, MySQL is UTF-8 aware. So, for example, a search for non-ASCII characters yields the correct result because the search is handled by MySQL rather than Wordpress.

share|improve this answer

No, WordPress doesn't support unicode natively. But it's an easy fix.

Open up your wp.config in your root.

Find these lines:

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

Just comment 'em out:

/** Database Charset to use in creating database tables. */
//define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
//define('DB_COLLATE', '');

Now it won't display unicode as a ? ... so you're all set.

share|improve this answer
    
I'm not sure you understood my question. Wordpress has multilingual support. You can have posts and so on in utf8. I want the database charset to be utf8 and collation to be utf_general_ci. I get that part. But I have studied Wordpress' PHP files and I don't see any mb_string functions, so I'm trying to understand how Wordpress is able to work with utf8 strings! – J Johnson Mar 23 '13 at 6:01

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.