爆炸成相等的部分

问题描述

|
$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个字爆炸一次?     

解决方法

        也许:?
<?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
然后“分割”结果数组:the5ѭ 然后您将
implode
array_map
应用于任何结果的单词组     ,        使用php
str_split
函数:-
$pieces = str_split( $str,3);