<?php
// ----------------------------------------------------------------------
// Copyright (C) 2006 by Khaled Al-Shamaa.
// http://www.al-shamaa.com/
// ----------------------------------------------------------------------
// LICENSE
// This program is open source product; you can redistribute it and/or
// modify it under the terms of the GNU General Public License (GPL)
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// To read the license please visit http://www.gnu.org/copyleft/gpl.html
// ----------------------------------------------------------------------
// Class Name: Detect Arabic String Character Set
// Filename: ArCharsetD.class.php
// Original Author(s): Khaled Al-Sham'aa <hide@address.com>
// Purpose: This class will return Arabic character set that used for
// a given Arabic string passing into this class, those available
// character sets that can be detected by this class includes
// the most popular three: Windows-1256, ISO 8859-6, and UTF-8.
// ----------------------------------------------------------------------
class ArCharsetD {
private function guess($string){
$charset['windows-1256'] = substr_count($string, 'Ç');
$charset['windows-1256'] += substr_count($string, 'á');
$charset['windows-1256'] += substr_count($string, 'í');
$charset['iso-8859-6'] = substr_count($string, 'Ç');
$charset['iso-8859-6'] += substr_count($string, 'ä');
$charset['iso-8859-6'] += substr_count($string, 'ê');
$charset['utf-8'] = substr_count($string, 'ا');
$charset['utf-8'] += substr_count($string, 'Ù');
$charset['utf-8'] += substr_count($string, 'Ù');
$total = $charset['windows-1256']+$charset['iso-8859-6']+$charset['utf-8'];
$charset['windows-1256'] = round($charset['windows-1256']*100/$total);
$charset['iso-8859-6'] = round($charset['iso-8859-6']*100/$total);
$charset['utf-8'] = round($charset['utf-8']*100/$total);
return $charset;
}
public function getCharset($string){
$charset = $this->guess($string);
arsort($charset);
return key($charset);
}
}
?>