0

i have a string like:

  $text = 'abc,xyz,wap+web+fbortworme';

in my achievement i want to be able explode + or , in the string line so my expected output we look like example:

  abc<br/>
  xyz<br/>
  wap<br/>
  web<br/>
  fb<br/>
  tw<br/>
  me<br/>

this my tried code:

  $text = 'abc,xyz,wap+web+fbortworme';
$plit = explode('+','or',',', $text);

foreach ($plit as $output) 
  {

  echo $output;

  }

but i get no output please see here https://ideone.com/8e4eOX

big thanks for your impact in my soluction

  • http://php.net/manual/en/function.preg-split.php –  Dec 17 '17 at 22:19
  • Possible duplicate of [How to split a string by multiple delimiters in PHP?](https://stackoverflow.com/questions/1452777/how-to-split-a-string-by-multiple-delimiters-in-php) – Nima Dec 17 '17 at 23:07
  • Possible duplicate of [Php multiple delimiters in explode](https://stackoverflow.com/questions/4955433/php-multiple-delimiters-in-explode) – Galen Dec 17 '17 at 23:29

1 Answers1

1

You can use preg_split function to do what you want

$text = 'abc,xyz,wap+web+fbortworme';
$splitted = preg_split('/[(or),\+]/', $text);
$splitted = array_filter($splitted); // remove any empty string

print_r($splitted);

This will output

Array
(
    [0] => abc
    [1] => xyz
    [2] => wap
    [3] => web
    [4] => fb
    [6] => tw
    [8] => me
)

And that's your expected output