コード例 #1
0
 function faviconCheck($ico)
 {
     if (substr($ico, 0, 3) == 'GIF' || substr($ico, 6, 4) == 'JFIF' || substr($ico, 1, 3) == 'PNG') {
         return true;
     }
     /* It could be a BMP. It would then start with 'BM',
      * followed by a magic 0 after 6 bytes and a magic 40 after
      * 14 bytes (see http://www.daubnet.com/formats/BMP.html)
      */
     if (strlen($ico) >= 40 && substr($ico, 0, 2) == 'BM' && SB_PageParser::bigEndianBin2long(substr($ico, 6, 4)) == 0 && SB_PageParser::bigEndianBin2long(substr($ico, 14, 4)) == 40) {
         // Highly probable that this is really a BMP
         return true;
     }
     /* It could also be ICO-format. It would then start with
      * a leading zero, followed by a magic 1.
      * (see http://www.daubnet.com/formats/ICO.html)
      */
     if (strlen($ico) >= 4 && SB_PageParser::bigEndianBin2short(substr($ico, 0, 2)) == 0 && SB_PageParser::bigEndianBin2short(substr($ico, 2, 2)) == 1) {
         // Check for the magic 40 after some header bytes
         $offset = SB_PageParser::bigEndianBin2short(substr($ico, 4, 2)) * 16;
         if (SB_PageParser::bigEndianBin2long(substr($ico, 6 + $offset, 4)) == 40) {
             // Highly probable that this is really an ICO
             return true;
         }
     }
     return false;
 }