title: How to pick part of text file in directory and print section with STRIPOS in PHP?
body: <p>I am trying to read text from files in a directory and have it be displayed as description text below an image.  I have been able to use the STRIPOS function to separate out each part of the text, except am having trouble with the last section.  The last section is titled "Description:" and actually runs into multiple lines.  I don't know how to display more than just the line that reads "Description:".  I want to print from "Description:" to the end of the file.  I will post my code and the text file in this message.</p>
  
  <pre><code>$dirname = 'data';
  
  $dirhandle = opendir($dirname);
  
  $housestextarray = array();
  
  if ($dirhandle)
          {
              while (false !==($file = readdir($dirhandle)))
              {
                  if ($file !='.' &amp;&amp; $file !='..')
                  {
                      array_push($housestextarray, $file);
                  }
              }
  
              closedir($dirhandle); 
          }
  
      sort($housestextarray);
  
  
      foreach ($housestextarray AS $housedescription)
          {
              $housetext = '';
  
              $description = '';
  
              $pos = stripos($housedescription, 'house_');
  
              if ($pos === false)
              {
                  //nothing
              } else {
                      $lines_in_file = count(file($housedescription));
  
                      $fp=fopen($housedescription,"r");
  
                      for ($cntr = 1; $cntr &lt;= $lines_in_file; $cntr++)
                  {
                      $cityline=fgets($fp);
                      $priceline=fgets($fp);
                      $bedroomsline=fgets($fp);
                      $bathsline=fgets($fp);
                      $footageline=fgets($fp);
                      $realtorline=fgets($fp);
                      $grabberline=fgets($fp);
  
                      $descriptionline=fgets($fp);
  
                      //print $cityline;
                      //print $descriptionline;
  
                      //$housetext .= $line;
  
                      $citypos = stripos($cityline, 'City:');
  
                      if ($citypos === false)  //found the city line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $city= $cityline."&lt;br /&gt;\n";
                          //print $city;
                      } 
  
                      $pricepos = stripos($priceline, 'Price:');
  
                      if ($pricepos === false)  //found the city line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $price = $priceline."&lt;br /&gt;\n";
                          //print $price;
                      } 
  
                      $bedroomspos = stripos($bedroomsline, 'Bedrooms:');
  
                      if ($bedroomspos === false)  //found the city line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $bedrooms = $bedroomsline."&lt;br /&gt;\n";
                          //print $bedrooms;
                      } 
  
                      $bathspos = stripos($bathsline, 'Baths:');
  
                      if ($bathspos === false)  //found the city line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $baths = $bathsline."&lt;br /&gt;\n";
                          //print $baths;
                      } 
  
                      $footagepos = stripos($footageline, 'Footage:');
  
                      if ($footagepos === false)  //found the city line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $footage = $footageline."&lt;br /&gt;\n";
                          //print $footage;
                      } 
  
                      $realtorpos = stripos($realtorline, 'Realtor:');
  
                      if ($realtorpos === false)  //found the realtor line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $realtor = $realtorline."&lt;br /&gt;\n";
                          //print $realtor;
                      } 
  
                      $grabberpos = stripos($grabberline, 'Grabber:');
  
                      if ($grabberpos === false)  //found the grabber line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $grabber_formatted = str_replace('Grabber:','', $grabberline);
                          $grabber = "&lt;h3&gt;".$grabber_formatted."&lt;/h3&gt;&lt;br /&gt;\n";
                          //print $grabber;
                      } 
  
                      $descriptionpos = stripos($descriptionline, 'Description: ');
                                                                      if ($descriptionpos === false)  //found the description line first time
                      {
                          //nothing
                      }
                      else
                      {
                          $description .= $descriptionline."&lt;br /&gt;";
  
                          //print $description;
  
                      }
                  }
                      $output = $grabber."&lt;br/&gt;".$city.$bedrooms.$baths;
                      $output .= $price.$footage.$realtor."&lt;br /&gt;";
                      $output .= "&lt;br /&gt;".$description."&lt;br /&gt;";
  
                      print $output;
  
              }   
  </code></pre>
  
  <p>And here is the text file contents example (one of six files):</p>
  
  <p>City: OceanCove <br />
  Price: $950,000<br />
  Bedrooms: 5<br />
  Baths: 3<br />
  Footage: 3000 sq. ft.<br />
  Realtor: Shirley Urkiddeng<br />
  Grabber: Fantastic Home with a Fantastic View!<br />
  Description: <br />
  You will never get tired of watching the sunset
  from your living room sofa or the sunrise
  from your back porch with a view overlooking
  the gorgeous coral canyon.  Once in a lifetime
  opportunity!</p>
  
  <p>UPDATED CODE WITH Branden's help:</p>
  
  <pre><code>    function houseDescriptions()
  {
      //$DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
      //$dirname = $DOCUMENT_ROOT.'data';
  $dirname = 'data';
  
  $dirhandle = opendir($dirname);
  
  $housestextarray = array();
  
  if ($dirhandle)
          {
              while (false !==($file = readdir($dirhandle)))
              {
                  if ($file !='.' &amp;&amp; $file !='..')
                  {
                      array_push($housestextarray, $file);
                  }
              }
  
              closedir($dirhandle); 
          }
  
      sort($housestextarray);
  
  
      foreach ($housestextarray AS $housedescription)
          {
                          $housetext = '';
  
                          $description = '';
  
                          $data ="";
  
                          $pos = stripos($housedescription, 'house_');
  
                          if ($pos === false)
                          {
                              //nothing
                          } else {
                              $file_handle = fopen($housedescription, "r");
                      $data = "";
                      while (!feof($file_handle)) {
                         $filestrings .= fgets($file_handle);
                      }
                      fclose($file_handle);
  
                      //You'll need to double check the Regex if it doesn't work.
                      $data = preg_split('#\b(City:|Bedrooms:|Baths:|Footage:|Realtor:|Grabber:|Description:)\b#', $filestrings);
  
                      $city = $data[0];
                      $bedrooms = $data[1];
                      $baths = $data[2];
                      $footage = $data[3];
                      $realtor = $data[4];
                      $grabber = $data[5];
                      $description = $data[6];                    
                      $output = $grabber."&lt;br /&gt;".$city.$bedrooms.$baths;
                      $output .= $price.$footage.$realtor."&lt;br /&gt;";
                      $output .= "&lt;br /&gt;".$description."&lt;br /&gt;";
  
                      print $output;
  
              }   
  
          }
          //return $output;
  }
  </code></pre>