language: PHP (php 5.4.4)
date: 562 days 17 hours ago
link:
visibility: public
1
2
3
4
5
6
7
<?php
$splitby = array('these','are','the','words','to','split','by');
$text = 'This is the string which needs to be split by the above words.';
$pattern = '/\s?'.implode($splitby, '\s?|\s?').'\s?/';
$result = preg_split($pattern, $text, -1, 1 /*PREG_SPLIT_NO_EMPTY*/);
var_dump($result);
?>