I have sentence like this:
I am in love with you
I want this to be in following combination for 3 words from left to right.
I am in
am in love
in love with
love with you
I tried the code below, but I think I'm complicating it...
$data = array_chunk(explode(" ", $sarr), 3);
$data = array_map(function($value) {
return sprintf("<span>%s</span>", implode(" ", $value));
}, $data);
echo implode("
", $data);
Any ideas on how to do it fast and efficiently? This must work for 5000 words.