How can explode() be used to split data from a TXT file into separate variables in PHP?
To split data from a TXT file into separate variables in PHP, you can use the explode() function to break the string into an array based on a specified delimiter. You can then assign each element of the array to a separate variable to store the data.
// Read the contents of the TXT file
$file_contents = file_get_contents('data.txt');
// Split the data into separate variables using explode()
$data_array = explode(',', $file_contents);
// Assign each element of the array to separate variables
$variable1 = $data_array[0];
$variable2 = $data_array[1];
$variable3 = $data_array[2];
// Now you can use $variable1, $variable2, $variable3 to access the split data