fork download
  1. <?php
  2. $data = '[xxx] test test[xxx]foobar
  3. more data
  4. [xxx] more data
  5. [xxx] other data []:foo bar
  6. more data here
  7. [xxx] 1234';
  8.  
  9. foreach(preg_split('/^(?=\[xxx] )/m', $data) as $el) {
  10. echo preg_replace('/\n(?!$)/', '\\n', $el);
  11. }
Success #stdin #stdout 0.03s 26128KB
stdin
Standard input is empty
stdout
[xxx] test test[xxx]foobar\nmore data
[xxx] more data
[xxx] other data []:foo bar\nmore data here
[xxx] 1234