How can the explode() function be used in PHP to split the contents of a text file into an array based on line breaks or other delimiters?
To split the contents of a text file into an array based on line breaks or other delimiters in PHP, you can use the explode() function. This function allows you to specify the delimiter (such as a line break "\n") and then splits the string into an array based on that delimiter. By reading the contents of the text file into a string variable, you can then use explode() to split it into an array of lines or other segments as needed.
// Read the contents of the text file into a string
$file_contents = file_get_contents('example.txt');
// Split the string into an array based on line breaks
$lines = explode("\n", $file_contents);
// Output each line in the array
foreach ($lines as $line) {
echo $line . "<br>";
}