php - Keep multi-character delimiter -
i have string
$string = "hi!n!my!n!name!n!is!n!bob";
i want split '!n!' i've tried like:
$splitstring = preg_split("!n!", $string,-1, preg_split_delim_capture);
but removes instances of 'n' instead of !n! if print_r
array, it'll like:
array( [0]=>hi! [1]=>!my! [2]=>! [3]=>!ame! [4]=>!is! [5]=>!bob )
it split every occurrence of 'n'. not !n! (a 3 character delimiter) wanted.
does know how solve this? in advance
you need delimiters (e.g. /
) in regular expression:
$splitstring = preg_split("/!n!/", $string,-1, preg_split_delim_capture);
Comments
Post a Comment