How does php judge that txt content is empty?

$content=file_get_contents($txt);
echo $content."<br>";
if(empty($content)){
    echo "0<br>";
}else{
    echo "1<br>";
}

Why output 1 whether there is content or not?

Php
Mar.07,2021

check that a file has no content, just use the filesize () function.

<?php
    if(filesize($txt) === 0){
        echo '';
    }
?>

if you have to write as you do, your judgment logic is wrong and not rigorous. The right thing to do is to judge the number of bytes of the string read, or compare it with the empty string'', but not with empty (), because, for example, if the content of the file is a number of zero zero empty (), it will return true.

.

$content = @file_get_contents($txt);
if($content === false){
    echo '';
}else{
    if(strlen($content) === 0){
        echo '';
    }else{
        echo '';
    }
}

? >


Please check whether there are spaces in the file, enter or tabs

Menu