$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);
This gives me:
$pieces[0] = 'Hello';
$pieces[1] = 'fri3nd,';
$pieces[2] = 'you\'re looking good today! What a Great day this is! How fancy and cool!';
How can I explode into every 3 or 4 words?
Maybe:?
<?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);
Explanation:
preg_split
array_chunk
implode
using array_map
on any resulting group of words