Код: Выделить всё
$productionCalendar = @file_get_contents('http://xmlcalendar.ru/data/ru/' . $this_year . '/calendar.xml');
Код: Выделить всё
$productionCalendar = @file_get_contents('http://xmlcalendar.ru/data/ru/' . $this_year . '/calendar.xml');
А вы в каком формате "подсовываете" этой функции $date ?webms писал(а):не хочет работать, помогите плз, куда копатьКод: Выделить всё
$productionCalendar = @file_get_contents('http://xmlcalendar.ru/data/ru/' . $this_year . '/calendar.xml');
Код: Выделить всё
weekDay(time());
Код: Выделить всё
$date = time();
weekDay($date);
webms писал(а):Не, проблема в другомСсылка да, открывается
Код: Выделить всё
$url = "http://xmlcalendar.ru/data/ru/2018/calendar.xml";
// Отключение ошибок libxml и передача полномочий по выборке и обработке информации об ошибках пользователю
libxml_use_internal_errors(true);
$res = @simplexml_load_file($url);
if( $res === false) {
echo 'Не удалось получить данные от сервиса xmlcalendar.';
foreach( libxml_get_errors() as $error ) {
echo $error->message;
}
libxml_clear_errors();
}
else {
//тут вытягиваем данные из xml-ки
var_dump($res);
}
Код: Выделить всё
object(SimpleXMLElement)#1 (3) { ["@attributes"]=> array(3) { ["year"]=> string(4) "2018" ["lang"]=> string(2) "ru" ["date"]=> string(10) "2017.10.22" } ["holidays"]=> object(SimpleXMLElement)#2 (1) { ["holiday"]=> array(8) { [0]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "1" ["title"]=> string(116) "Новогодние каникулы (в ред. Федерального закона от 23.04.2012 № 35-ФЗ)" } } [1]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "2" ["title"]=> string(35) "Рождество Христово" } } [2]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "3" ["title"]=> string(46) "День защитника Отечества" } } [3]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "4" ["title"]=> string(50) "Международный женский день" } } [4]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "5" ["title"]=> string(41) "Праздник Весны и Труда" } } [5]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "6" ["title"]=> string(21) "День Победы" } } [6]=> object(SimpleXMLElement)#10 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "7" ["title"]=> string(21) "День России" } } [7]=> object(SimpleXMLElement)#11 (1) { ["@attributes"]=> array(2) { ["id"]=> string(1) "8" ["title"]=> string(44) "День народного единства" } } } } ["days"]=> object(SimpleXMLElement)#3 (1) { ["day"]=> array(26) { [0]=> object(SimpleXMLElement)#11 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.01" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [1]=> object(SimpleXMLElement)#10 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.02" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [2]=> object(SimpleXMLElement)#9 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.03" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [3]=> object(SimpleXMLElement)#8 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.04" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [4]=> object(SimpleXMLElement)#7 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.05" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [5]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.06" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [6]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.07" ["t"]=> string(1) "1" ["h"]=> string(1) "2" } } [7]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "01.08" ["t"]=> string(1) "1" ["h"]=> string(1) "1" } } [8]=> object(SimpleXMLElement)#12 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "02.22" ["t"]=> string(1) "2" } } [9]=> object(SimpleXMLElement)#13 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "02.23" ["t"]=> string(1) "1" ["h"]=> string(1) "3" } } [10]=> object(SimpleXMLElement)#14 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "03.07" ["t"]=> string(1) "2" } } [11]=> object(SimpleXMLElement)#15 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "03.08" ["t"]=> string(1) "1" ["h"]=> string(1) "4" } } [12]=> object(SimpleXMLElement)#16 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "03.09" ["t"]=> string(1) "1" } } [13]=> object(SimpleXMLElement)#17 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "04.28" ["t"]=> string(1) "2" } } [14]=> object(SimpleXMLElement)#18 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "04.30" ["t"]=> string(1) "1" } } [15]=> object(SimpleXMLElement)#19 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "05.01" ["t"]=> string(1) "1" ["h"]=> string(1) "5" } } [16]=> object(SimpleXMLElement)#20 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "05.02" ["t"]=> string(1) "1" } } [17]=> object(SimpleXMLElement)#21 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "05.08" ["t"]=> string(1) "2" } } [18]=> object(SimpleXMLElement)#22 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "05.09" ["t"]=> string(1) "1" ["h"]=> string(1) "6" } } [19]=> object(SimpleXMLElement)#23 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "06.09" ["t"]=> string(1) "2" } } [20]=> object(SimpleXMLElement)#24 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "06.11" ["t"]=> string(1) "1" } } [21]=> object(SimpleXMLElement)#25 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "06.12" ["t"]=> string(1) "1" ["h"]=> string(1) "7" } } [22]=> object(SimpleXMLElement)#26 (1) { ["@attributes"]=> array(3) { ["d"]=> string(5) "11.04" ["t"]=> string(1) "1" ["h"]=> string(1) "8" } } [23]=> object(SimpleXMLElement)#27 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "11.05" ["t"]=> string(1) "1" } } [24]=> object(SimpleXMLElement)#28 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "12.29" ["t"]=> string(1) "2" } } [25]=> object(SimpleXMLElement)#29 (1) { ["@attributes"]=> array(2) { ["d"]=> string(5) "12.31" ["t"]=> string(1) "1" } } } } }
Код: Выделить всё
object(SimpleXMLElement)#1 (3) { ["@attributes"]=> array(3) { ["year"]=> string(4) "2018" ["lang"]=> string(2) "ru" ["date"]=> string(10) "2017.10.22" } ["holidays"]=> object(SimpleXMLElement)#2 ....
В else вместо var_dump вставитьwebms писал(а):ЗаработалА подскажите пожалуйста как привязать код выше с кодом https://majordomo.smartliving.ru/forum/ ... 172#p37320?
Код: Выделить всё
//Проверяем сегодняшний день по производственному календарю (рабочий или нет)
$weekDay = -1;
$this_date = date('m.d', $date);
foreach ($res->days->day as $day) {
$type = $day->attributes()->t; //тип дня: 1 - выходной день, 2 - короткий день, 3 - рабочий день (суббота/воскресен)
echo $type . PHP_EOL;
$CalDate = $day->attributes()->d; //дата
echo $CalDate . PHP_EOL;
if ($this_date == $CalDate) {
if ($type == 1) { //выходной
$weekDay = 0;
} elseif ($type == 2) {
//Короткий день
//$weekDay = 1;
} elseif ($type == 3) { //Перенесенный рабочий
$weekDay = 0;
}
}
}
//Если в производственном календаре ничего не нашлось
if ($weekDay == -1) {
if (date('w', $date) == 0 || date('w', $date) == 6) {
$weekDay = 0;
} else {
$weekDay = 1;
}
}
Код: Выделить всё
if ($сегодняшнийДень == weekDay(time()) { echo 'выходной';}
elseif ($завтрашнийДень == weekDay(strtotime("+1 day")) { echo 'выходной';}