Resmi Tatil Günlerini Bulma

 

<?php
$yil=date("Y");//2020
function clean($str)
{ 
$str = json_encode($str);
$str = str_replace("\u00a0", " ", $str);
$str = json_decode($str);
return $str;
}
header('Content-Type: text/html; charset=utf-8');
function resarch($needle, $haystack, $currentKey = '') {
foreach($haystack as $key=>$value) {
if (is_array($value)) {
$nextKey = resarch($needle,$value, $currentKey . $key);
if ($nextKey) {
return $nextKey;
}
}
else if($value==$needle) {
return is_numeric($key) ? $currentKey : $currentKey ;
}
}
return false;
}
header('Content-Type: text/html; charset=utf-8');
libxml_use_internal_errors(true);
$hosting="http://www2.diyanet.gov.tr";
$url=$hosting."/DinHizmetleriGenelMudurlugu/Sayfalar/ResmiTatilGunlerinListesi.aspx";
$string = file_get_contents($url, false, null, -1);
preg_match_all( '/\/([^"]*)'.$yil.'([^"]*)aspx"/i', $string, $output);
$tatilliste=$hosting.str_replace('%2F','/',urlencode(str_replace('"',"",$output[0][0])));
$string = file_get_contents($tatilliste, false, null, -1);
$dom = new DOMDocument;
$dom->loadHTML( $string );
$rows = array();
$x=0;
foreach($dom->getElementsByTagName( 'tr' ) as $tr ) {
$x++;

$cells = array();
if($x>3){
foreach( $tr->getElementsByTagName( 'td' ) as $td ) {
$cells[] = str_replace(array("&nbsp;","&#8203","\xE2\x80\x8C","\xE2\x80\x8B",),array(' ','','',''),$td->nodeValue);
}
$rows[] = $cells;
}

}
$c=resarch('CUMHURİYET BAYRAMI', $rows);
$e=$rows[$c];
unset($rows[$c]);
$f1=explode(' ',$e[2]);
$f2=explode("\r\n",$e[3]);
$rows[]=array($e[0],$e[1],$f1[0]." ".$f1[1],$f2[0]);
$rows[]=array($e[0],$e[1],str_replace("\r\n",'',($f1[2]." ".$f1[3])),$f2[1]);
$aylar=array('','OCAK','ŞUBAT','MART','NİSAN','MAYIS','HAZİRAN','TEMMUZ','AĞUSTOS','EYLÜL','EKİM','KASIM','ARALIK');
$data=array();
foreach($rows as $r){
$gun=explode(' ',clean($r[2]));
$ay=array_search($gun[1],$aylar);
$tm=strtotime($gun[0]."-".$ay."-2020");
$tarih=date("Y-m-d",$tm);
$data[]=array($r[0],$r[1],$r[2],$r[3],$tarih,$tm);
}
print_r($data);

Çıktısı

Array
(
    [0] => Array
        (
            [0] => EMEK VE DAYANIŞMA GÜNÜ*
            [1] => 1 GÜN
            [2] => 01 MAYIS
            [3] => CUMA
            [4] => 2020-05-01
            [5] => 1588284000
        )

    [1] => Array
        (
            [0] => ATATÜRK'Ü ANMA GENÇLİK VE SPOR BAYRAMI 
            [1] => 1 GÜN
            [2] => 19 MAYIS
            [3] => SALI
            [4] => 2020-05-19
            [5] => 1589839200
        )

    [2] => Array
        (
            [0] => RAMAZAN BAYRAMI AREFESi
            [1] => 1/2 GÜN
            [2] => 23 MAYIS
            [3] => CUMARTESİ
            [4] => 2020-05-23
            [5] => 1590184800
        )

    [3] => Array
        (
            [0] => RAMAZAN BAYRAMI
            [1] => 1. GÜN
            [2] => 24 MAYIS
            [3] => PAZAR
            [4] => 2020-05-24
            [5] => 1590271200
        )

    [4] => Array
        (
            [0] => RAMAZAN BAYRAMI
            [1] => 2. GÜN
            [2] => 25 MAYIS
            [3] => PAZARTESİ
            [4] => 2020-05-25
            [5] => 1590357600
        )

    [5] => Array
        (
            [0] => RAMAZAN BAYRAMI 
            [1] => 3. GÜN
            [2] => 26 MAYIS
            [3] => SALI
            [4] => 2020-05-26
            [5] => 1590444000
        )

    [6] => Array
        (
            [0] => DEMOKRASİ VE MİLLİ BİRLİK GÜNÜ*
            [1] => 1 GÜN
            [2] => 15 TEMMUZ
            [3] => ÇARŞAMBA
            [4] => 2020-07-15
            [5] => 1594764000
        )

    [7] => Array
        (
            [0] => KURBAN BAYRAMI AREFESi

            [1] => 1/2 GÜN
            [2] => 30 TEMMUZ
            [3] => PERŞEMBE
            [4] => 2020-07-30
            [5] => 1596060000
        )

    [8] => Array
        (
            [0] => KURBAN BAYRAMI 
            [1] => 1. GÜN
            [2] => 31 TEMMUZ
            [3] => CUMA
            [4] => 2020-07-31
            [5] => 1596146400
        )

    [9] => Array
        (
            [0] => KURBAN BAYRAMI 
            [1] => 2. GÜN
            [2] => 01 AĞUSTOS
            [3] => CUMARTESİ
            [4] => 2020-08-01
            [5] => 1596232800
        )

    [10] => Array
        (
            [0] => KURBAN BAYRAMI 
            [1] => 3. GÜN
            [2] => 02 AĞUSTOS
            [3] => PAZAR
            [4] => 2020-08-02
            [5] => 1596319200
        )

    [11] => Array
        (
            [0] => KURBAN BAYRAMI 
            [1] => 4. GÜN
            [2] => 03 AĞUSTOS
            [3] => PAZARTESİ
            [4] => 2020-08-03
            [5] => 1596405600
        )

    [12] => Array
        (
            [0] => ZAFER BAYRAMI 
            [1] => 1 GÜN
            [2] => 30 AĞUSTOS
            [3] => PAZAR
            [4] => 2020-08-30
            [5] => 1598738400
        )

    [13] => Array
        (
            [0] => CUMHURİYET BAYRAMI
            [1] => 1,5 GÜN
            [2] => 28 EKİM
            [3] => ÇARŞAMBA
            [4] => 2020-10-28
            [5] => 1603839600
        )

    [14] => Array
        (
            [0] => CUMHURİYET BAYRAMI
            [1] => 1,5 GÜN
            [2] => 29 EKİM
            [3] => PERŞEMBE
            [4] => 2020-10-29
            [5] => 1603926000
        )

)

Sizin Değerli Görüşlerinize İhtiyacımız Var.