What are some alternatives to the file() function in PHP for splitting lines into array elements?

The file() function in PHP reads a file and splits its contents into an array, with each line of the file becoming an element in the array. However, the file() function is not always the most efficient or secure method for handling file operations. An alternative approach is to use the file_get_contents() function to read the file contents into a string, and then use the explode() function to split the string into an array based on a delimiter, such as a newline character.

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