Suppose I have a string like this:
Ch #RoKamb93 ajesop de Bourg #kin #kinnl 9 kunsho taffetas,bunughs rges, note florale,parfaite aseref
My array of delimiters can be :
array('#kin', '#kinnl', '#xxx' );
How can Iparse it to get the Ch #RoKamb93 ajesop de Bourg substring ? Substring just before #kin OR #kinnl
Note: Both #kin OR #kinnl may not present at the same time.
How about this:
$string = 'Ch #RoKamb93 ajesop de Bourg #kin #kinnl 9 kunsho taffetas,bunughs rges, note florale,parfaite aseref';
$delimiters = array('#kin', '#kinnl', '#xxx');
$pattern = '/' . implode($delimiters, '|') . '/';
$split = preg_split($pattern, $string);
var_dump($split); // $split[0] has what you need
If your delimiters contain reserved regex characters (like .
or ?
), you'll need to do something like this for the pattern:
$pattern = '/' . implode(array_map('preg_quote', $delimiters), '|') . '/';