[ create a new paste ] login | about

Link: http://codepad.org/GuPiSSnS    [ raw code | output | fork ]

PHP, pasted on Aug 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
    
$someBigString = <<<SAMPLE
  This, actually, is a 'nice' old'er string, as they said, "divided and conquered".
SAMPLE;

// change this to whatever you need to:     
$number_of_words = 6; 

$arr = preg_split("#([a-z]+[a-z'-]*(?<!['-]))#i", 
      $someBigString, $number_of_words + 1, PREG_SPLIT_DELIM_CAPTURE);
    
$res = implode('', array_slice($arr, 0, $number_of_words * 2));
echo $res;


Output:
1
  This, actually, is a 'nice' old'er


Create a new paste based on this one


Comments: