How can you handle cases where there are spaces within the data you want to extract from a text file in PHP?

When extracting data from a text file in PHP that contains spaces within the data, you can use functions like `explode()` or `preg_split()` to split the data based on a specific delimiter, such as a comma or a tab. Alternatively, you can use functions like `trim()` to remove any leading or trailing spaces from the extracted data.

$file = fopen("data.txt", "r");

while (!feof($file)) {
    $line = fgets($file);
    $data = explode(",", $line); // Split data based on comma
    $cleanedData = array_map('trim', $data); // Remove leading and trailing spaces
    // Process cleaned data
}

fclose($file);