language: PHP (php 5.4.4)
date: 561 days 5 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.';
$pieces = preg_split('/'.implode('\s*|\s*',$splitby).'/',$text,-1,PREG_SPLIT_NO_EMPTY);
var_dump($pieces);