Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 171 lines (167 sloc) 5.68 KB
<?php
#http://persiangd.berlios.de
#Copyright (C) 2007 Milad Rastian (miladmovie[_at_]gmail)
#thanks to Bagram Siadat (info[_at_]gnudownload[_dot_]org) (bug fix and new developer)
#tahanks to Ramin Farmani (bug fix)
#
#This program is free software; you can redistribute it and/or
#modify it under the terms of the GNU General Public License
#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.
#
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
function utf8_strlen($str) {
return preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $dummy);
}
$p_chars = array (
'آ' => array ('', '', 'آ'),
'ا' => array ('', '', 'ا'),
'ب' => array ('', '', ''),
'پ' => array ('', '', ''),
'ت' => array ('', '', ''),
'ث' => array ('', '', ''),
'ج' => array ('', '', ''),
'چ' => array ('', '', ''),
'ح' => array ('', '', ''),
'خ' => array ('', '', ''),
'د' => array ('', '', ''),
'ذ' => array ('', '', ''),
'ر' => array ('', '', ''),
'ز' => array ('', '', ''),
'ژ' => array ('', '', ''),
'س' => array ('', '', ''),
'ش' => array ('', '', ''),
'ص' => array ('', '', ''),
'ض' => array ('', '', 'ﺿ'),
'ط' => array ('', '', ''),
'ظ' => array ('', '', ''),
'ع' => array ('', '', ''),
'غ' => array ('', '', ''),
'ف' => array ('', '', ''),
'ق' => array ('', '', ''),
'ک' => array ('', '', ''),
'گ' => array ('', '', ''),
'ل' => array ('', '', ''),
'م' => array ('', '', ''),
'ن' => array ('', '', ''),
'و' => array ('', '', ''),
'ی' => array ('', 'ﯿ', ''),
'ك' => array ('', '', ''),
'ي' => array ('', '', ''),
'أ' => array ('', '', ''),
'ؤ' => array ('', '', ''),
'إ' => array ('', '', ''),
'ئ' => array ('', '', ''),
'ة' => array ('', '', '')
);
$nastaligh = array(
'ه' => array ('', '', '')
);
$normal = array(
'ه' => array ('', '', '')
);
$mp_chars = array ('آ', 'ا', 'د', 'ذ', 'ر', 'ز', 'ژ', 'و', 'أ', 'إ', 'ؤ');
$ignorelist = array('','ٌ','ٍ','ً','ُ','ِ','َ','ّ','ٓ','ٰ','ٔ','','','','','','','','','','','','','',);
///
function fagd($str,$z="",$method='normal'){
global $p_chars,$mp_chars, $ignorelist,$nastaligh,$normal;
if($method == 'nastaligh'){
$p_chars = array_merge($p_chars,$nastaligh);
}elsE{
$p_chars = array_merge($p_chars,$normal);
}
$str_len=utf8_strlen($str);
preg_match_all("/./u", $str, $ar);
for ($i=0; $i<$str_len; $i++){
$str1=$ar[0][$i];
if(in_array($ar[0][$i+1],$ignorelist)){
$str_next=$ar[0][$i+2];
if ($i == 2) $str_back=$ar[0][$i-2];
if ($i != 2) $str_back=$ar[0][$i-1];
}elseif(!in_array($ar[0][$i-1],$ignorelist)){
$str_next=$ar[0][$i+1];
if ($i != 0) $str_back=$ar[0][$i-1];
}else{
if(isset($ar[0][$i+1]) && !empty($ar[0][$i+1])){
$str_next=$ar[0][$i+1];
}else{
$str_next=$ar[0][$i-1];
}
if ($i != 0) $str_back=$ar[0][$i-2];
}
if(!in_array($str1,$ignorelist)){
if (array_key_exists($str1,$p_chars)){
if(!$str_back or $str_back==" " or !array_key_exists($str_back,$p_chars)){
if(!array_key_exists($str_back,$p_chars) and !array_key_exists($str_next,$p_chars)) $output=$str1.$output;
else $output=$p_chars[$str1][2].$output;
continue;
}elseif (array_key_exists($str_next,$p_chars) and array_key_exists($str_back,$p_chars)){
if(in_array($str_back,$mp_chars) and array_key_exists($str_next,$p_chars)){
$output=$p_chars[$str1][2].$output;
}else{
$output=$p_chars[$str1][1].$output;
}
continue;
}elseif(array_key_exists($str_back,$p_chars) and !array_key_exists($str_next,$p_chars)){
if(in_array($str_back,$mp_chars)){
$output=$str1.$output;
}else{
$output=$p_chars[$str1][0].$output;
}
continue;
}
}elseif($z=="fa"){
$number =array("٠","١","٢","٣","٤","٥","٦","٧","٨","٩","۴","۵","۶","0","1","2","3","4","5","6","7","8","9");
switch ($str1){
case ")" : $str1="("; break;
case "(" : $str1=")"; break;
case "}" : $str1="{"; break;
case "{" : $str1="}"; break;
case "]" : $str1="["; break;
case "[" : $str1="]"; break;
case ">" : $str1="<"; break;
case "<" : $str1=">"; break;
}
if(in_array($str1,$number)){
$num.=$str1;
$str1="";
}
if (!in_array($str_next,$number)){
$str1.=$num;
$num="";
}
$output=$str1.$output;
}else{
if(($str1=="،") or ($str1=="؟") or ($str1=="ء") or (array_key_exists($str_next,$p_chars) and array_key_exists($str_back,$p_chars)) or
($str1==" " and array_key_exists($str_back,$p_chars)) or ($str1==" " and array_key_exists($str_next,$p_chars)))
{
if($e_output){
$output=$e_output.$output;
$e_output="";
}
$output=$str1.$output;
}
else{
$e_output.=$str1;
if(array_key_exists($str_next,$p_chars) or $str_next==""){
$output=$e_output.$output;
$e_output="";
}
}
}
}else{
$output=$str1.$output;
}
$str_next = null;
$str_back = null;
}
return $output;
}
?>