0

I want explode a string to array with 2 dashes or more. For example I have a string such as "size--medium" or "size---medium" or "size----medium" or this pattern with more than 2 dashes, I want explode them to:

Array(
    0 => size,
    1 => medium
);

Thanks guys

Pooya Saberian
  • 971
  • 2
  • 9
  • 16

1 Answers1

2

Just split the input string according to two or more dashes.

<?php
$yourstring = "size----medium";
$regex = '~-{2,}~';
$splits = preg_split($regex, $yourstring);
print_r($splits);
?>

Output:

Array
(
    [0] => size
    [1] => medium
)
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274