Remove the Chinese special characters from the PHP string

Source: Internet
Author: User
Now there is a Chinese character like this "Hello!" 】

I now want to put the Chinese character ""! Remove (of course not just these 3 types)

What should we do?

Reply content:

Now there is a Chinese character like this "Hello!" 】

I now want to put the Chinese character ""! Remove (of course not just these 3 types)

What should we do?

Keep only Chinese words


  
  

比较简单的就是用preg_replace做了,虽然你指出不止那几个字符,但是中文符号也没几个吧,不防可以都打上的说,去除也可以,或者替换成因为的也成。

echo preg_replace('/[【!】]/', '', '【你好!】');

OR

$preg = array('【','】','!');$replace = array('[', ']', '!');function add_slash($item)   return '/'.$item.'/';$preg = array_map('add_slash', $preg);echo preg_replace($preg, $replace, '【你好!】');
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.