I am working on Japanese language web site, and using this code for words limit, it is working when I paste English sentence but not working with Japanese words .
function content($num) {
$theContent = get_the_content();
$output = preg_replace('/<img[^>]+./','', $theContent);
$output = preg_replace( '/<blockquote>.*</blockquote>/', '', $output );
$output = preg_replace( '|[(.+?)](.+?[/\1])?|s', '', $output );
$limit = $num+1;
$content = explode(' ', $output, $limit);
array_pop($content);
$content = implode(" ",$content)."...";
echo $content;
}
<?php content('15'); ?>
Can any body help me, and one thing is that I am using xeory_extension
theme.
The problem is that Japanese characters are multibyte (Hiragana and Katakana characters are stored on 3 bytes in UTF-8), so you’ll have to use special php multibytes string functions to manipulate strings that contains Japanese characters.
Sadly PHP doesn’t provide a
mb_explode
function out of the box. Though some people worked on that, usingmb_strlen
andmb_substr
to build up that missing function.The following code is note mine, it comes from the fetus-hina mb_explode gist:
Then just use it the same way you use explode:
And for
implode
, you shouldn’t have any issue.This worked for me