There is no problem not worth solving, and no technology not worth learning!

The result of preg_split after executing Chinese is garbled

preg_split 执行中文后的结果,有乱码。

1. The result of preg_split after executing Chinese is garbled. as shown in Figure 1

preg_split 执行中文后的结果,有乱码。
Figure 1

$optionText = '多选一,多选二';
$optionInputs = preg_split('/[\r\n,,;;、]+/', $optionText);


2. Convert the string to UTF-8 before using preg_split(). u means Unicode (UTF-8) mode, avoiding Chinese character split errors.


$optionText = mb_convert_encoding('多选一,多选二', 'UTF-8', 'auto');
$optionInputs = preg_split('/[\r\n,,;;、]+/u', $optionText);



3, the split is correct, no more errors.


Array ( [0] => 多选一 [1] => 多选二 )


Need long-term technical maintenance or remote troubleshooting?

I am a PHP / Go backend engineer with 15+ years of experience, focused on existing system maintenance, bug fixing, performance optimization, server troubleshooting, WordPress maintenance, and small feature iterations.

If your project is facing any of the following issues, we can start with a small troubleshooting task first:

  • ✅ PHP / Laravel / Yii2 legacy systems without active maintenance
  • ✅ Go / Gin backend APIs that need troubleshooting or optimization
  • ✅ Slow, broken, or unstable WordPress websites
  • ✅ Nginx / MySQL / Redis / Linux server issues
  • ✅ CDN / Cloudflare / DNS / HTTPS configuration problems
  • ✅ Long-term remote technical support or part-time maintenance

More details: About Me & Collaboration

WeChat: 13980074657
Email: shuijingwanwq@gmail.com
Telegram: @shuijingwan
GitHub: https://github.com/shuijingwan

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.