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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb1ee9-2392.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb1ee9-2392.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?