webHauser Blog

Icon

Welcome to webHauser weblog

How to split a text file into lines using explode()

Here’s how to split a text file into lines using explode(). This could be very useful for restoring backed up databases, when you need to pass every line (SQL statement) to MYSQL separatly:

$theFile = file_get_contents('file.txt');
$lines = array();
$lines = explode("\n", $theFile);
$lineCount = count($lines);
for ($i = 0; $i < $lineCount; $i++){
  echo $lines[$i]."<hr>";
} //for

Leave a Reply

You must be logged in to post a comment.