fork download
  1. <?php
  2.  
  3. $str= "[As 4h 8s] [ As 4h ] [As4h] As [ 4h ";
  4.  
  5. preg_match_all("/\[([^\]]+)\]/", $str, $matches);
  6. $values = $matches[1];
  7. $result = [];
  8. foreach($values as $value)
  9. {
  10. $parts = preg_split("/ /", $value, -1, PREG_SPLIT_NO_EMPTY);
  11. foreach($parts as $part)
  12. {
  13. array_push($result, $part);
  14. }
  15. }
  16. var_dump($result);
Success #stdin #stdout 0.04s 52480KB
stdin
Standard input is empty
stdout
array(6) {
  [0]=>
  string(2) "As"
  [1]=>
  string(2) "4h"
  [2]=>
  string(2) "8s"
  [3]=>
  string(2) "As"
  [4]=>
  string(2) "4h"
  [5]=>
  string(4) "As4h"
}