fork download
  1. <?php
  2.  
  3. $string = "02/12/2018 (Assessment 2) = /86= | Weight: 50.00%";
  4. $array = explode(" ", $string);
  5.  
  6. forEach($array as $item){
  7. // verifica quantas barras "\" a string possui
  8. preg_match_all("~\/~", $item, $matches);
  9.  
  10. // se tiver 2 barras é uma data
  11. if(sizeof($matches[0]) == 2){
  12. $dados[ "date" ] = $item;
  13. }
  14.  
  15. if(sizeof($matches[0]) == 1){
  16. $mark = explode("/", $item);
  17. // se o primerio estiver vazio, retorna 00.00
  18. $dados[ "markOK" ] = $mark[0] ? $mark[0] : "00.00";
  19. $dados[ "markTotal" ] = $mark[1];
  20. }
  21.  
  22. if(strrpos($item, "%")){
  23. $dados[ "weight" ] = str_replace("%", "", $item);
  24. }
  25. }
  26.  
  27. var_dump($dados);
Success #stdin #stdout 0s 82624KB
stdin
Standard input is empty
stdout
array(4) {
  ["date"]=>
  string(10) "02/12/2018"
  ["markOK"]=>
  string(5) "00.00"
  ["markTotal"]=>
  string(3) "86="
  ["weight"]=>
  string(5) "50.00"
}