fork download
  1. <?php
  2.  
  3. $in = fopen('php://stdin', "r");
  4. $out = fopen('php://stdout', "w");
  5.  
  6. $data = "";
  7. while (false !== ($in = fgets(STDIN))) {
  8. $data .= $in;
  9. }
  10.  
  11. $rx = '/(<S\w{9}\sw\w{8}=\"\w{4,5}\">)(\W{1,2}M\w{14}>)(.*)(<\/M\w{14}>)(.*)\W+(<\/S\w{9}>)/im';
  12. $re = preg_replace($rx, "$2$3$4\n $1$5$6", $data);
  13.  
  14. echo($re);
  15.  
Success #stdin #stdout 0.01s 20520KB
stdin
<StartMonthGroup>
   <StartMonth withdrawn="false"><MajorOfferRound>12 Dec 2013</MajorOfferRound>Sep 2013
   </StartMonth>
   <StartMonth withdrawn="false">Jan 2014</StartMonth>
   <StartMonth withdrawn="false">May 2014</StartMonth>
</StartMonthGroup>
<StartMonthGroup>
   <StartMonth withdrawn="true"><MajorOfferRound>12 Dec 2013</MajorOfferRound>Sep 2013
   </StartMonth>
   <StartMonth withdrawn="true">Jan 2014</StartMonth>
   <StartMonth withdrawn="true">May 2014</StartMonth>
</StartMonthGroup>
stdout
<StartMonthGroup>
   <MajorOfferRound>12 Dec 2013</MajorOfferRound>
   <StartMonth withdrawn="false">Sep 2013</StartMonth>
   <StartMonth withdrawn="false">Jan 2014</StartMonth>
   <StartMonth withdrawn="false">May 2014</StartMonth>
</StartMonthGroup>
<StartMonthGroup>
   <MajorOfferRound>12 Dec 2013</MajorOfferRound>
   <StartMonth withdrawn="true">Sep 2013</StartMonth>
   <StartMonth withdrawn="true">Jan 2014</StartMonth>
   <StartMonth withdrawn="true">May 2014</StartMonth>
</StartMonthGroup>