Categories

Explode A File Example

The test text file was actually an article, this example will look for full stops in the text and output each line as a new line.

<?php
   $file = file_get_contents(“test.txt”);

   $contents = explode(“.”,$file);
   foreach ($contents as $content)
   {
   echo “$content<br/>”;
   }
?>

Read a text file into an array

Read a text file into an array

<?php
   $file = file_get_contents(“test.txt”);

   // Place the contents of test.txt in an array
   $contents = explode(“\n”,$file);

   foreach ($contents as $content)
   {
      echo “$content”;
   }
?>