Splitting a string into bi-grams in PHP

Using explode makes it easy enough:

$string="I have had the greatest {A} {B} day yesterday {C}";

$words=explode(" ",$string);

$filtered_words=array();

foreach($words as $w)
{
  if(!preg_match("/{.*}/",$w))
  {
    array_push($filtered_words,$w);
  }
}


$output=array();

foreach(range(0,count($filtered_words)-2) as $i)
{
  array_push($output,$filtered_words[$i] . "-" . $filtered_words[$i+1]);
}

var_dump($output);

The output is:

array(6) {
  [0]=>
  string(6) "I-have"
  [1]=>
  string(8) "have-had"
  [2]=>
  string(7) "had-the"
  [3]=>
  string(12) "the-greatest"
  [4]=>
  string(12) "greatest-day"
  [5]=>
  string(13) "day-yesterday"
}

Source: php – Splitting a string into bi-grams, ignoring certain labels – Stack Overflow