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:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24147219.html

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')
<?php
	
// Reading file
$sFileName = 'utf8.txt';
$hFile = fopen($sFileName, 'rb');
$contents = fread($hFile, filesize($sFileName));
fclose($hFile);
 
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
hankknightAsked:
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.  
0
 
Ray PaseurCommented:
Thanks!  Best regards, ~Ray
0
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.