How to use the explode function in PHP using 2 delimeters instead of 1? -


suppose have following:

$string = "(a) (b) (c)"; 

how explode contents inside parenthesis. if string's contents separated 1 symbol instead of 2 have used:

$string = "a-b-c"; explode("-", $string); 

but how when 2 delimiters used encapsulate items exploded?

you have use preg_split or preg_match instead.

example:

$string = "(a) (b) (c)"; print_r(preg_split('/\\) \\(|\\(|\\)/', $string, -1, preg_split_no_empty)); 
 array (     [0] =>     [1] => b     [2] => c ) 

notice order important.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -