$str = "Hello fri3nd, you're looking good today! What a Great day this is! How fancy and cool!";
$pieces = explode(" ",$str, 3);
print_r($pieces);
所以这给了我$pieces[0] = 'Hello',
$ pieces [1] ='fri3nd'... and the rest of the string is all shoved into
$ pieces [3]`。如何在每3或4个单词中爆炸?
答案 0 :(得分:2)
也许:
<?php
$str = "Hello fri3nd, you're looking good today! What a Great day this is! How fancy and cool!";
$array = array_map(create_function('$a', 'return implode(" ", $a);'), array_chunk(preg_split('/\s+/', $str), 3));
var_dump($array);
说明:
preg_split
array_chunk
implode
对任何结果字词组array_map
答案 1 :(得分:1)
使用php str_split
功能: -
$pieces = str_split( $str, 3);