Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add a space between a Chinese character and a letter or a number to make the article more readable.

For example:

Google与Apple展开的专利大战在2天之前结束。

Google 与 Apple 展开的专利大战在 2 天之前结束。

But add the space manually is a hard work. How can I do it automatically? Maybe with CSS?

share|improve this question
1  
Wow, a heck of a Question! Would be nice if you added related resources that you found while researching for this problem. ::: I only know of one person who can answer this. ::: And it would not be CSS (maybe impossible?), but WP/PHP... –  brasofilo Jan 21 '13 at 8:42

1 Answer 1

up vote 5 down vote accepted

Interesting question. This could be a useful part of a specific language file. It cannot be done in CSS, because CSS is (mostly) character agnostic. But using a filter and PHP it is possible and on topic:

add_filter( 'the_content', 't5_chinese_spacing' );

function t5_chinese_spacing( $content )
{
    return preg_replace(
        '~([^\p{Han}]*)(\p{Han}+)([^\p{Han}])~imUxu',
        '\1 \2 \3',
        $content
    );
}

Be aware your internal encoding has to be UTF-8 to make that work. While WordPress works with other encodings too, PHP needs UTF-8 for this. Read WordPress Database Charset and Collation Configuration to make sure everything is set up properly.

Also note I am using PHP’s character class for Han unification here. This is not perfect, some punctuation marks Chinese writers might use are not included.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.