pastebin

Paste Search Dynamic
Recent pastes
preg_match_all
  1. <?php
  2.  
  3. $str = "Apr 20 01:58:54 seccubi td-agent-bit[24759]: [2020/04/20 01:58:54] [ warn] [engine] chunk '24759-1587347923.381728950.flb' cannot be retried: task_id=1, input=tail.0 > output=http.0";
  4.  
  5. //(preg_match_all("~\[[^\]]+\]|\w+=\w+~",$str, $data));
  6.  
  7. $time = microtime(true);
  8.  
  9. for ($i = 0;$i<10000;++$i){
  10. preg_match_all("~\[[^\]]+\]|\w+=\w+~",$str, $data);
  11.  
  12. $result = [];
  13. $data = array_shift($data);
  14. $cnt = count($data);
  15. for ($j=0;$j<$cnt;++$j) {
  16.        
  17.         $x = trim(ltrim(rtrim($data[$j],']'),'['));
  18.         if(is_numeric($x)) {
  19.                 continue;
  20.         }
  21.         $x = explode('=', $x);
  22.         $result[$x[0]] = $x[1] ?? '_';//isset($x[1]) ? $x[1] : '_';
  23. }
  24. }
  25.  
  26. var_dump( microtime(true) - $time);
  27.  
  28.  
  29. $time = microtime(true);
  30. $cb = function($item) {
  31.         if (is_numeric($item)) {
  32.                 return false;
  33.         }
  34.         return $item;
  35. };
  36. for ($i = 0;$i<10000;++$i){
  37. (preg_match_all("~\[([^\]]+)\]|(\w+)=(\w+)~",$str, $data));
  38. $data1 = array_filter(array_map("trim", $data[1]), $cb);
  39. $data2 = array_filter($data[2]);
  40. $data3 = array_filter($data[3]);
  41. (array_merge(array_fill_keys($data1, '_'), array_combine($data2, $data3)));
  42. }
  43.  
  44. var_dump( microtime(true) - $time);
  45.  
  46. ?>
Parsed in 0.026 seconds