title: Large XML file Parsing Chunk data Filetering in PHP
body: <p>I have a large XML file more than 100 MB. I am reading the file in chunks like this</p>
  
  <blockquote>
    <p>$fp = fopen('large.xml', 'r');</p>
    
    <p>while ($data = fread($fp, 4096)) {</p>
  </blockquote>
  
  <p>The format of XML is like this</p>
  
  <pre><code>&lt;PersonalInfo&gt;
      &lt;UserDetail&gt;
         &lt;FirstName&gt;ABC&lt;/FirstName&gt;
         &lt;Occupation&gt;Student&lt;/Occupation&gt;
         &lt;DateOfBirth&gt;08/14/1999&lt;/DateOfBirth&gt;
      &lt;/UserDetail&gt;
      &lt;CaseDetail&gt;....&lt;/CaseDetail&gt;
      &lt;TransactionDetail&gt;....&lt;/TransactionDetail&gt;
  &lt;/PersonalInfo&gt;      
  &lt;PersonalInfo&gt;
      &lt;UserDetail&gt;
         &lt;FirstName&gt;XYZ&lt;/FirstName&gt;
         &lt;Occupation&gt;Student&lt;/Occupation&gt;
         &lt;DateOfBirth&gt;04/25/1991&lt;/DateOfBirth&gt;
       &lt;/UserDetail&gt;
       &lt;CaseDetail&gt;....&lt;/CaseDetail&gt;
       &lt;TransactionDetail&gt;.....&lt;/TransactionDetail&gt;
  &lt;/PersonalInfo&gt;      
  &lt;PersonalInfo&gt;
      &lt;UserDetail&gt;
          &lt;FirstName&gt;DEF&lt;/FirstName&gt;
          &lt;Occupation&gt;Teacher&lt;/Occupation&gt;
          &lt;DateOfBirth&gt;05/12/1984&lt;/DateOfBirth&gt;
      &lt;/UserDetail&gt;
      &lt;CaseDetail&gt;....&lt;/CaseDetail&gt;
      &lt;TransactionDetail&gt;...&lt;/TransactionDetail&gt;
  &lt;/PersonalInfo&gt;   
  </code></pre>
  
  <p>I want to just include those records where the Occupation TAG is "Student"  and write those results to a CSV file. </p>
  
  <p>I have tried the preg_match as
  preg_match( "/\(.*?)\&lt;/PersonalInfo>/s", $data, $match );
  to select the Tags and then look into $match but it is returning double values(repetition). </p>