Hello, I looking for a piece of code to chop a string into a array with 2 or more delimiters
example:
this is the text and I want to chop [!FIRST!] here and a bit later [!LAST!] here and if its posible (its not required) [!OPTIONAL!] chop it here

and store this in a array like

array(
       [0] => "this is the text and I want to chop "
       [1] => "[!FIRST!]"
       [2] => " here and a bit later "
       [3] => "[!LAST!]"
       [4] => " here and if its posible (its not required) "
       [5] => "[!OPTIONAL!]"
       [6] => " chop it here"
)

If someone can help me with it please

grtz Nestiq

Use preg_split:

$arr = preg_split('\[!(FIRST|LAST|OPTIONAL)!\]', $text);

Use preg_split:

$arr = preg_split('\[!(FIRST|LAST|OPTIONAL)!\]', $text);

I never worked with preg_split before, I dont know how it works so I did not think about that, unfortinately I got this error when trying it out:

Warning: preg_split() [function.preg-split]: Delimiter must not be alphanumeric or backslash in C:\xampp\htdocs\test.php on line 18

Oops, forgot the delimiters.

$arr = preg_split('/\[!(FIRST|LAST|OPTIONAL)!\]/', $text);

Oops, forgot the delimiters.

$arr = preg_split('/\[!(FIRST|LAST|OPTIONAL)!\]/', $text);

Thanks :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.