コード例 #1
0
ファイル: SampleTest.php プロジェクト: saeedazizi/farsi
 public function sample_5()
 {
     print StringCleaner::digitsToFarsi('1394');
     print "\n";
     print StringCleaner::digitsToEnglish('۱۳۹۴');
     print "\n";
     print StringCleaner::arabicToFarsi('كيك پي اچ پي چيست؟');
     print "\n";
 }
コード例 #2
0
ファイル: JalaliParser.php プロジェクト: saeedazizi/farsi
 /**
  * @param string $format
  * @param string $date
  * @throw InvalidArgumentException
  * @return JalaliDate
  */
 public static function createJalaliFromFormat($format, $date)
 {
     $dateParts = new DateParts();
     $regexp = '';
     $matchCount = 0;
     $escaped = false;
     $functions = str_split($format);
     foreach ($functions as $function) {
         if ($escaped) {
             $regexp .= preg_quote($function);
             $escaped = false;
         } elseif ($function === '\\') {
             $escaped = true;
         } elseif ($function === '.') {
             $regexp .= '.';
         } elseif ($function === '*') {
             $regexp .= '.*';
         } elseif ($function === '/') {
             $regexp .= '\\/';
         } elseif (array_key_exists($function, static::$conversionFunctions)) {
             $f = static::$conversionFunctions[$function];
             $regexp .= '(' . static::$f($dateParts, $matchCount) . ')';
         } else {
             $regexp .= preg_quote($function);
         }
     }
     if ($dateParts->isAmbiguous()) {
         throw new InvalidArgumentException();
     }
     $regexp = "/^{$regexp}\$/";
     $date = StringCleaner::digitsToEnglish($date);
     if (!preg_match($regexp, $date, $matches)) {
         throw new InvalidArgumentException();
     }
     $dateParts->fillWithMatches($matches);
     return $dateParts->createJalaliDate();
 }
コード例 #3
0
 public function test_convert_digits_to_English()
 {
     $this->assertEquals('09134107', $this->cleaner->digitsToEnglish('۰۹۱۳۴۱۰۷'));
     $this->assertEquals('09134107', $this->cleaner->digitsToEnglish('۰۹۱۳۴۱0۷'));
     $this->assertEquals('09134107abcd', $this->cleaner->digitsToEnglish('۰۹۱۳۴۱0۷abcd'));
 }