0

I am trying to split my string where you see the phrase %3B and &. I am a little confused with the pattern. Here is my code

$string = '123123123%3B123123213%3B&action=123123%3B34234234'
print_r(preg_split('/[(%3B|&)]/', $string));
Yuri
  • 89
  • 1
  • 7
  • `preg_split('/(%3B|&)/', $string)` should be better ? as misorude said below, grouping is also useless in that case. – Frankich Jan 22 '19 at 09:11
  • 1
    `[…]` means a _character class_, so you are allowing it to split on each single one of those characters. As @MacBooc said, you want that without those. Grouping might not be necessary either, `/%3B|&/` should do. – misorude Jan 22 '19 at 09:12
  • If you do not need the use of regular expressions, you can use the explode function - in your case, twice, because you have two delimiters (http://php.net/manual/en/function.explode.php). – proprit Jan 22 '19 at 12:37

0 Answers0