我会将句子分成以下单词:
例如:
结果:
例如:
This is a test from php, python, asp and also from other languages. Alash! i cannot get my output as followings.
结果:
结果:
array(
[0]=>"This",
[1]=>"is",
[2]=>"a",
[3]=>"test",
[4]=>"from",
[5]=>"php",
[6]=>",",
[7]=>"python",
[8]=>",",
[9]=>"asp",
[10]=>"and",
[11]=>"also",
[12]=>"from",
[13]=>"other",
[14]=>"languages",
[15]=>".",
[16]=>"Alash",
[17]=>"!",
[18]=>"I",
[19]=>"cannot",
[20]=>"get",
...
)
在php中,我的选项有哪些?
/\s+|\b(?=\W)/
,这样就不会得到那么多空字符串了。 - mhyfritzperl -e "print join'#', split /\s+|\b/, 'foo, bar baz! k'"
给出的结果是foo#,#bar#baz#!#k
,没有任何空格。我猜PHP的split函数工作方式不同。 - Qtax