Posted by petersprc on 02/17/07 20:01
Hi,
The "file" command on unix should tell you if the file is text or
binary.
You could also do it with a regexp:
$isBinary = preg_match('/[^\x08\t\n\r\f\x20-\x7e]/',
file_get_contents('/the/file'));
(By the way, less can be made to stop warning you by using the -f
option: less -f /usr/local/bin/php)
On Feb 17, 2:15 pm, Schraalhans Keukenmeester <bitbuc...@invalid.spam>
wrote:
> Is it possible in PHP to determine whether a file is (intended as)
> binary or ascii data other than by examining its extension? I can't find
> a ready-made function or script online that does so.
>
> If I open a file with less on my linux box for example it warns when it
> 'thinks' it's binary rather than ascii.
>
> TIA.
> Sh.
[Back to original message]
|