犹太日期演示编码问题

时间:2012-06-24 19:23:52

标签: php date

  

可能重复:
  UTF-8 all the way through

我正在尝试将当前日期转换为当前的犹太日期。为了做到这一点,我找到了this php函数。但是,当我将代码打印到屏幕上时,我在屏幕上看到的只有奇怪的字符。经过更多调查后,我发现只有当我循环一系列日期时才会发生这种情况。

举例说明:

代码示例1

我的代码:

$aJulianFormat = array('month'=>date('m'), 'day'=>date('d'), 'year' => date('Y'));
$jewishDate = jdtojewish(
               gregoriantojd($aJulianFormat['month'], 
                             $aJulianFormat['day'],
                             $aJulianFormat['year']),
                             true,
                             CAL_JEWISH_ADD_GERESHAYIM + 
                             CAL_JEWISH_ADD_ALAFIM + 
                             CAL_JEWISH_ADD_ALAFIM_GERESH
              );
echo('jdtojewish' . ' : ' . $jewishDate . '<br>');
echo('iconv' . ' : ' . iconv('ISO-8859-8', 'UTF-8', $jewishDate) . '<br>');

输出:

jdtojewish: ' ' “

iconv:ד'תמוזה'אלפיםתשע"ב&lt; -----这是必需的输出,这很好。

代码示例2

    $aDates = $this->createDateRangeArray('2012-09-01', '2013-09-01');
    foreach ($aDates as $aDate) {

        $aJulianFormat = $this->splitDate($aDate);
        //         $aJulianFormat = array('month'=>date('m'), 'day'=>date('d'), 'year' => date('Y'));
        $jewishDate = jdtojewish(
                gregoriantojd($aJulianFormat['month'], 
                        $aJulianFormat['day'], 
                        $aJulianFormat['year']), 
                        true, 
                        CAL_JEWISH_ADD_GERESHAYIM +
                        CAL_JEWISH_ADD_ALAFIM +
                        CAL_JEWISH_ADD_ALAFIM_GERESH
        );
        echo('jdtojewish' . ' : ' . $jewishDate . '<br>');
        echo('iconv' . ' : ' . iconv('ISO-8859-8', 'UTF-8', $jewishDate) . '<br>');

    }

输出

  

jdtojewish:é“ãàìåìä'ààôéíúùò”áiconv:×™“×”×לולד'

     

×לפי×תשע“×'jdtojewish:è”åàìåìä'ààôéíúùò“áiconv:

     

×〜“ו××××××××××××××××××××××××××××××××××××××××××'××      

úùò“áiconv:×〜”× - ×לולד×לפי×תשע”×'jdtojewish:é“æ

     

àìåìä'àìôéíúùò“áiconv:×™”× - ×לולד'×לפי×תשע”×'

     

jdtojewish:é“çàìåìä'àìôéíúùò”áiconv:×™“× - ×לולה'

     

×× - פי×תשע“×'jdtojewish:é”èàìåìääààôéíúùò“áiconv:

     

×™“×〜××××××××××××××××××××××××××      

úùò“áiconv:×>'×לולה×לפי×תשע“×'jdtojewish:ë”à

     

àìåìä'àìôéíúùò“áiconv:×>”××××ולד'×לפי×תשע”×'

     

jdtojewish:ë“áàìåìä'ààôéíúùò”áiconv:×>“×'×לולה'

     

×לפי×תשע“×'jdtojewish:ë”â€ì'àìäàà'ôéíúùò“á

     

等...

这是错误的/不是必需的输出。

似乎编码出了问题。

对于有兴趣的人,我在这里发布了我的完整代码:http://pastebin.com/kc2LHPrg

<?php

namespace Luach\Controller;

use Zend\Mvc\Controller\ActionController,
    Zend\View\Model\ViewModel;

class LuachController extends ActionController {

    public function indexAction() {
        $aDates = $this->createDateRangeArray('2012-09-01', '2013-09-01');
        foreach ($aDates as $aDate) {

            $aJulianFormat = $this->splitDate($aDate);
            //         $aJulianFormat = array('month'=>date('m'), 'day'=>date('d'), 'year' => date('Y'));
            $jewishDate = jdtojewish(
                    gregoriantojd($aJulianFormat['month'], 
                            $aJulianFormat['day'], 
                            $aJulianFormat['year']), 
                            true, 
                            CAL_JEWISH_ADD_GERESHAYIM +
                            CAL_JEWISH_ADD_ALAFIM +
                            CAL_JEWISH_ADD_ALAFIM_GERESH
            );
            echo('jdtojewish' . ' : ' . $jewishDate . '<br>');
            echo('iconv' . ' : ' . iconv('ISO-8859-8', 'UTF-8', $jewishDate) . '<br>');

        }


    }

    private function createDateRangeArray($strDateFrom, $strDateTo) {
        // takes two dates formatted as YYYY-MM-DD and creates an
        // inclusive array of the dates between the from and to dates.
        // could test validity of dates here but I'm already doing
        // that in the main script

        $aryRange = array();

        $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2), substr($strDateFrom, 8, 2), substr($strDateFrom, 0, 4));
        $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2), substr($strDateTo, 8, 2), substr($strDateTo, 0, 4));

        if ($iDateTo >= $iDateFrom) {
            array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry

            while ($iDateFrom < $iDateTo) {
                $iDateFrom+=86400; // add 24 hours
                array_push($aryRange, date('Y-m-d', $iDateFrom));
            }
        }
        return $aryRange;
    }

    private function splitDate($sDate) {

        return date_parse_from_format("Y-m-d", $sDate);

    }

}

任何人都知道第二个代码示例中出了什么问题?

非常感谢。

0 个答案:

没有答案