What are the best practices for handling variable lengths in PHP when reading from a file like gb.txt?

When reading from a file like gb.txt in PHP, it is important to handle variable lengths of lines correctly to avoid data truncation or errors. One way to do this is by reading the file line by line and using functions like `fgets()` or `file()` to handle lines of different lengths. Additionally, you can use functions like `trim()` to remove any extra whitespace at the beginning or end of each line.

$file = fopen('gb.txt', 'r');

if ($file) {
    while (($line = fgets($file)) !== false) {
        $trimmedLine = trim($line);
        // Process the trimmed line here
    }
    fclose($file);
} else {
    echo "Error opening file.";
}