title: preg_replace causing browser error
body: <p>I have a web app written in PHP that needs to parse data files. It uses preg_replace to get rid of any column headings etc. at the top of the file and then loops through the rest of the file line by line, using preg_match to pull out the relevant values on each line.</p>
  
  <p>Here is the format of the file:</p>
  
  <pre><code>Column heading 1  Column heading 2  Column heading 3 Column heading 4
         0.000000000E+0000     0.000000000E+0000     0.000000000E+0000     0.000000000E+0000  
         0.000000000E+0000     0.000000000E+0000     0.000000000E+0000     0.000000000E+0000  
         0.000000000E+0000     0.000000000E+0000     0.000000000E+0000     0.000000000E+0000  
         0.000000000E+0000     0.000000000E+0000     0.000000000E+0000     0.000000000E+0000  
         0.000000000E+0000     0.000000000E+0000     0.000000000E+0000     0.000000000E+0000  
  </code></pre>
  
  <p>There could be up to 10,000 rows of data in the file. I have just had a customer ask if I can only match the last row of data, rather than taking data from every row.</p>
  
  <p>Therefore I need a regex to remove the column headings and every line of data except the last one. Here is the code I am using:</p>
  
  <pre><code>$startsWith = "/^Column heading 1  Column heading 2  Column heading 3 Column heading 4\r\n(   [0-9]{1}\.[0-9]{9}E[\+-][0-9]{4}     [0-9]{1}\.[0-9]{9}E[\+-][0-9]{4}     [0-9]{1}\.[0-9]{9}E[\+-][0-9]{4}     [0-9]{1}\.[0-9]{9}E[\+-][0-9]{4}  \r\n(?!$))*/s";
  
  $str = preg_replace($startsWith,'',$str);
  </code></pre>
  
  <p>This should leave me with only the last line of data. This works absolutely fine if I run the script through command-line PHP. However if I run it through the browser I get no response from the server - just a blank page. </p>
  
  <p>I have seen this question already: <a href="https://stackoverflow.com/questions/7620910/regexp-in-preg-match-function-returning-browser-error">RegExp in preg_match function returning browser error</a></p>
  
  <p>But it doesn't really help as lowering the <code>pcre.recursion_limit</code> just causes the regex not to work at all, and come back with a <code>PREG_RECURSION_LIMIT_ERROR</code> error.</p>
  
  <p>Is there a more efficient way, using regex, to trim everything except the last line of data in a large file? Or some settings I can tweak to make it work through Apache?</p>
  
  <h1>Update</h1>
  
  <p>Thanks for everyone's suggestions but, because of the way the system's built, I NEED to use regex. For parsing this particular file it's not ideal I know, but for other file types it's the only way. The system is built to parse many very odd file types and regex was the only way of achieving this. The regex I supplied works when running through PHP CLI, but not through a web page - is there a more efficient regex or some settings I can change to make it work through Apache?</p>