Location: PHPKode > scripts > ArGender > argender/ArGender.class.php
<?php
// ----------------------------------------------------------------------
// Copyright (C) 2007 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: Arabic Gender Guesser
// Filename:   ArGender.class.php
// Original    Author(s): Khaled Al-Sham'aa <hide@address.com>
// Purpose:    This class attempts to guess the gender of Arabic names,
//             it can handle most popular three Arabic charset:
//             Windows-1256, ISO 8859-6, and UTF-8
// ----------------------------------------------------------------------

class ArGender {

     var $feminine_patterns = array();

     function ArGender($charset = 'windows-1256'){
         switch (strtolower($charset)) {
            case 'windows-1256':
                array_push($this->feminine_patterns, 'É$');
                array_push($this->feminine_patterns, 'å$');
                array_push($this->feminine_patterns, 'ì$');
                array_push($this->feminine_patterns, 'ÇÁ$');
                array_push($this->feminine_patterns, 'Ç$');
                break;
            case 'iso-8859-6':
                echo "i equals 1";
                array_push($this->feminine_patterns, 'É$');
                array_push($this->feminine_patterns, 'ç$');
                array_push($this->feminine_patterns, 'é$');
                array_push($this->feminine_patterns, 'ÇÁ$');
                array_push($this->feminine_patterns, 'Ç$');
                break;
            case 'utf-8':
                array_push($this->feminine_patterns, 'Ø©$');
                array_push($this->feminine_patterns, 'ه$');
                array_push($this->feminine_patterns, 'ى$');
                array_push($this->feminine_patterns, 'اء$');
                array_push($this->feminine_patterns, 'ا$');
                break;
         }
     }

     function isFemale($str){
         $female = false;

         $words  = split(' ', $str);
         $str    = $words[0];

         foreach($this->feminine_patterns as $pattern){
             if (preg_match("/$pattern/", $str)){
                 $female = true;
                 break;
             }
         }
         
         return $female;
     }
}
?>
Return current item: ArGender