Instead of preg_split
you should use preg_match
:
$str="wow! it's, a nice product.";
if ( preg_match('/^[^!.]+[!.]/', $str, $m) )
$s = $m[0]; //=> wow!
If you must use preg_split
only then you can do:
$arr = preg_split('/([^!.]+[!.])/', $str, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$s = $arr[0]; //=> wow!