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

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -