Checking hex to verify UTF-8: is uppercase required?

LordOfPorts provided me with a way to verify if a file was saved in Notepad with UTF-8 encoding:

His example used strtoupper.  Is that required?  

Could I use this:
       if(substr(bin2hex($contents), 0, 6) === 'efbbbf')
instead of this?
       if(strtoupper(substr(bin2hex($contents), 0, 6)) === 'EFBBBF')
// Reading file
$sFileName = 'utf8.txt';
$hFile = fopen($sFileName, 'rb');
$contents = fread($hFile, filesize($sFileName));
if(strtoupper(substr(bin2hex($contents), 0, 6)) === 'EFBBBF')
	echo 'UTF-8 encoded file recognized.';
	else echo 'Not recognized as a UTF-8 encoded file.';

Open in new window

LVL 16
Who is Participating?
Ray PaseurCommented:
In this context, strtoupper is like having a belt and suspenders.  It's safer that way.  Either the lower case or the uppercase is acceptable output from bin2hex.  
Ray PaseurCommented:
Thanks!  Best regards, ~Ray
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.