fork download
  1. <?php
  2.  
  3. $file = '[trace-123] <request>This is a log line</request>
  4. [trace-124] <reply>This is another log line
  5.  
  6. this is part of "[trace-124]" still.</reply>
  7. [trace-125] <request>final log line.</request>';
  8.  
  9. $tracePattern = "/\[trace-[0-9]*+\]+\s*<(?:reply|request)>.*?<\/(?:reply|request)>/s";
  10.  
  11. preg_match_all($tracePattern,$file,$lines);
  12.  
  13. $lines = $lines[0]; // by defaults, $lines[0] will be an array of the matches, so get that
  14.  
  15. echo "<pre>";print_r($lines);echo "</pre>";
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [0] => [trace-123] <request>This is a log line</request>
    [1] => [trace-124] <reply>This is another log line
    
    this is part of "[trace-124]" still.</reply>
    [2] => [trace-125] <request>final log line.</request>
)
</pre>