Possible Duplicate:
UTF-8 all the way through
I am trying to convert the current date to the current jewish date. In order to do this I found this php function. However when I print the code to my screen I see only weird charachters on my screen. After more investigation I found out this only happends when I loop through an array of dates.
To illustrate:
Code sample 1
My Code :
$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>');
The output:
jdtojewish : �' ���� �' ����� ���"�
iconv : ד' תמוז ה' אלפים תשע"ב <----- this is the required output which is good.
Code sample 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>');
}
The output
jdtojewish : é"ã àìåì ä' àìôéí úùò"á iconv : ×™"ד ×לול ×”'
××œ×¤×™× ×ª×©×¢"ב jdtojewish : è"å àìåì ä' àìôéí úùò"á iconv :
ט"ו ×לול ×”' ××œ×¤×™× ×ª×©×¢"ב jdtojewish : è"æ àìåì ä' àìôéí
úùò"á iconv : ט"×– ×לול ×”' ××œ×¤×™× ×ª×©×¢"ב jdtojewish : é"æ
àìåì ä' àìôéí úùò"á iconv : ×™"×– ×לול ×”' ××œ×¤×™× ×ª×©×¢"ב
jdtojewish : é"ç àìåì ä' àìôéí úùò"á iconv : ×™"×— ×לול ×”'
××œ×¤×™× ×ª×©×¢"ב jdtojewish : é"è àìåì ä' àìôéí úùò"á iconv :
×™"ט ×לול ×”' ××œ×¤×™× ×ª×©×¢"ב jdtojewish : ë' àìåì ä' àìôéí
úùò"á iconv : ×›' ×לול ×”' ××œ×¤×™× ×ª×©×¢"ב jdtojewish : ë"à
àìåì ä' àìôéí úùò"á iconv : ×›"× ×לול ×”' ××œ×¤×™× ×ª×©×¢"ב
jdtojewish : ë"á àìåì ä' àìôéí úùò"á iconv : ×›"ב ×לול ×”'
××œ×¤×™× ×ª×©×¢"ב jdtojewish : ë"â àìåì ä' àìôéí úùò"á
etc....
This is all wrong / not the required output.
It seems that something is going wrong with the encoding.
For those who are interested I have posted here my full code: 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);
}
}
Anyone a clue what's going wrong in the second code sample?
Thanks very much.