What are the potential pitfalls of using fgets to read files line by line in PHP?

One potential pitfall of using `fgets` to read files line by line in PHP is that it includes the newline character at the end of each line, which may lead to unexpected behavior when processing the data. To solve this issue, you can use the `trim` function to remove any leading or trailing whitespace, including the newline character, from each line read by `fgets`.

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

if ($file) {
    while (($line = fgets($file)) !== false) {
        $line = trim($line); // Remove leading and trailing whitespace
        // Process the line here
    }
    fclose($file);
}