fork download
  1. <?php
  2.  
  3. $string = "One two three four five six seven eight nine ten.";
  4.  
  5. // the first number words to extract
  6. $n = 2;
  7.  
  8. // extract the words
  9. $words = explode(" ", $string);
  10.  
  11. for($i=0; $i<=$n-1; $i++) {
  12. $firstCount[] = ' ' .$words[$i]; // This will return one, two
  13. }
  14.  
  15. for($i =$n; $i<count($words); $i++) {
  16. $lastCount[] = ' ' . $words[$i]; // This will return three four five six seven eight nine ten
  17. }
  18.  
  19. print_r($firstCount);
  20. print_r($lastCount);
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] =>  One
    [1] =>  two
)
Array
(
    [0] =>  three
    [1] =>  four
    [2] =>  five
    [3] =>  six
    [4] =>  seven
    [5] =>  eight
    [6] =>  nine
    [7] =>  ten.
)