如何解决爆炸成相等的部分
|$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
应用于任何结果的单词组
, 使用phpstr_split
函数:-
$pieces = str_split( $str,3);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。