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?
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.