How can we read a line from a text file in PHP and compare it with another variable value?

To read a line from a text file in PHP and compare it with another variable value, you can use the `fgets()` function to read a line from the file and then compare it with the desired variable using a conditional statement like `if`. You can open the file using `fopen()` and close it using `fclose()` once you have finished reading the file.

$file = fopen("example.txt", "r"); // Open the file for reading

if($file){
    $line = fgets($file); // Read a line from the file
    $variable = "example"; // Variable value to compare with

    if($line == $variable){
        echo "The line from the file matches the variable value.";
    } else {
        echo "The line from the file does not match the variable value.";
    }

    fclose($file); // Close the file
} else {
    echo "Error opening the file.";
}