$s = "FrontPage 2000ä¸æçæç¨å¤§å¨";
print_r(preg_match_all('/./u', $s, $matches));
echo "\n";
print_r($matches);
?>
将给予
21
Array
(
[0] => Array
(
[0] => F
[1] => r
[2] => o
[3] => n
[4] => t
[5] => P
[6] => a
[7] => g
[8] => e
[9] =>
[10] => 2
[11] => 0
[12] => 0
[13] => 0
[14] => ä¸
[15] => æ
[16] => ç
[17] => æ
[18] => ç¨
[19] => 大
[20] => å¨
)
)
请注意,我的源代码也存储在用UTF-8编码的文件中,以便$s包含这些字符。
$s = "FrontPage 2000ä¸æçæç¨å¤§å¨";
print_r(preg_match_all('/(\w+)|(.)/u', $s, $matches));
echo "\n";
print_r($matches[0]);
?>
结果:
10
Array
(
[0] => FrontPage
[1] =>
[2] => 2000
[3] => ä¸
[4] => æ
[5] => ç
[6] => æ
[7] => ç¨
[8] => 大
[9] => å¨
)