Jump to content

PHP - Detecting and removing Japanese/Chinese characters in a title string


ocpaul20

Recommended Posts

I have a string of mixed Japanese or Chinese and Western characters and I would really like to leave the western characters and remove the others. Is there any way to detect which UTF-8 characters are Japanese/Chinese and to remove them?

 

I have tried to use this which I found on another thread but my version of PHP (5.3) will not allow the /u in the following

echo "<BR>".preg_replace('/[^\u4E00-\u9FFF]+/', '', $string);

 

I have tried using various combinations of /p (these, plus others)

echo "<BR>".preg_replace('/\p{Bopomofo}+/u', '', $string);
echo "<BR>".preg_replace('/\p{Hiragana}+/u', '', $string);

and the /x{} option tells me the numbers are to large

echo "<BR>".preg_replace('/[^\x{4E00}-\x{9FFF}]+/', '', $string);

 

My string for this example is this but any combination of western and Japanese/Chinese characters are possible in the title.

2011.12.06 19:00-20:00 / ãµãã„ã¡ãƒ©ã‚¤ãƒ–カメラ (Live Fukushima Nuclear Plant Cam) | Uploaded: 06 Dec 2011

 

Thanks for any help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.