Split string with multiple delimiters in PHP

Is it possible to parse strings in an array based on multiple delimiters? as described in the code:

$str ="a,bc,d;ef"; //What i want is to convert this string into array //using the delimiters space, comma, semicolon 
+4
source share
2 answers

Php

 $str = "a,bc,d;ef"; $pieces = preg_split('/[, ;]/', $str); var_dump($pieces); 

CodePad

Output

 array(6) { [0]=> string(1) "a" [1]=> string(1) "b" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "e" [5]=> string(1) "f" } 
+16
source

Source: https://habr.com/ru/post/1345038/


All Articles