How to Check if File is ASCII or Binary in PHP

后端 未结 5 2046
说谎
说谎 2020-12-03 14:23

Is there a quick, simple way to check if a file is ASCII or binary with PHP?

5条回答
  •  不思量自难忘°
    2020-12-03 15:04

    this way it seems ok in my project:

    function probably_binary($stringa) {
        $is_binary=false;
        $stringa=str_ireplace("\t","",$stringa);
        $stringa=str_ireplace("\n","",$stringa);
        $stringa=str_ireplace("\r","",$stringa);
        if(is_string($stringa) && ctype_print($stringa) === false){
            $is_binary=true;
        }
        return $is_binary;
    }
    

    PS: sorry, my first post, I wanted to add a comment to previous one :)

提交回复
热议问题