#!/usr/bin/php
<?php // version="4+"

   /*
    *   Guess codepage
    *   A tool which determines in which codepage is the input
    *
    *   (C) 2005, Rozsnyo Daniel <daniel@rozsnyo.com>
    *
    */

    // init
    
$pocet = array();
    for(
$i=0$i<=255$i++) $pocet[$i] = 0;

    
// histogram    
    
if ($handle fopen('php://stdin','rb')) {
        while((
$c=fgetc($handle))!==false$pocet[ord($c)]++;
        
fclose($handle);
    }

    
// pro nas zajimave indice
    
$iso $pocet[0xA9]+$pocet[0xAE]+$pocet[0xB9]+$pocet[0xBE];
    
$utf $pocet[0xC3]+$pocet[0xC4]+$pocet[0xC5]+$pocet[0xC6];
    
$win $pocet[0x8A]+$pocet[0x8E]+$pocet[0x9A]+$pocet[0x9E];
    
    
// odhad UTF8
    
if (($utf>$iso) && ($utf>$win)) die("UTF-8\n");
    
    
// zbyle porovname (a vetsi sance at ma windows)
    
die( ($iso>$win) ? "ISO-8859-2\n" "WINDOWS-1250\n" );
    
?>