How can PHP's explode function be used to split text from a file into separate pieces?

To split text from a file into separate pieces using PHP's explode function, you can read the file contents into a string variable and then use explode to split the text based on a delimiter, such as a newline character or a specific word. This will create an array of separate pieces of text that you can then process individually.

$file_contents = file_get_contents('example.txt');
$pieces = explode("\n", $file_contents);

foreach ($pieces as $piece) {
    // Process each piece of text here
    echo $piece . "<br>";
}