fork download
  1. <?php
  2.  
  3. $inputWords = mb_split('\s+', 'If you want to have a preformatted block...');
  4. $forbiddenWords = array("want", "have");
  5.  
  6. $filtered = array_diff($inputWords, $forbiddenWords); // removes blacklisted
  7.  
  8. $pairs = array_chunk($filtered, 2); // array of arrays
  9. $pairs = array_map(function($a) { return implode(' ', $a); }, $pairs);
  10.  
  11. print_r($pairs);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => If you
    [1] => to a
    [2] => preformatted block...
)