$sub= ‘我有5斤大米,6斤白面,售卖100元’;

我想提取”有5斤大米”、”卖100元”,用preg_match_all( ‘/.?\d+.?/’, $sub, $match)出现乱码

改成preg_match_all( ‘/.?\d+.?/u’, $sub, $match)后正常。

这里的小写字母u是修饰符,表示把字符当utf-8处理。

官方文档:https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php